Services & Resources / Wolfram Forums
MathGroup Archive
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2003

[Date Index] [Thread Index] [Author Index]

Search the Archive

two's complement function

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

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]]


  • Prev by Date: Negation of Negation wanted
  • Next by Date: Re: M5.0 keyboard shortcuts with linux
  • Previous by thread: Re: Negation of Negation wanted
  • Next by thread: Re: two's complement function