two's complement function

*To*: mathgroup at smc.vnet.net*Subject*: [mg44035] two's complement function*From*: "Ken Morgan" <kemorgan at vt.edu>*Date*: Sat, 18 Oct 2003 03:12:38 -0400 (EDT)*Organization*: Virginia Tech, Blacksburg, Virginia, USA*Sender*: owner-wri-mathgroup at wolfram.com

Can anyone think of a better way to produce a list of digits of a two's complement integer than the following? tc[n_, bits_:32] := If[Positive[n], IntegerDigits[n, 2, bits], IntegerDigits[FromDigits[IntegerDigits[n, 2, bits] /. {1 -> 0, 0 -> 1}, 2] + 1, 2, bits]] Thanks, Ken

**Follow-Ups**:**Re: two's complement function***From:*"Peter Pein" <nospam@spam.no>