Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2003
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*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

Re: two's complement function

  • To: mathgroup at smc.vnet.net
  • Subject: [mg44049] Re: two's complement function
  • From: "Peter Pein" <nospam at spam.no>
  • Date: Sun, 19 Oct 2003 01:10:48 -0400 (EDT)
  • References: <200310180712.DAA28084@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

tc[n_, bits_:32] :=
   If[n >= 0, IntegerDigits[n, 2, bits],
      1 - IntegerDigits[2^bits - n + 1, 2, bits]]

Peter Pein, Berlin
petsie at arcAND.de
replace && by || to write to me


----- Original Message -----
From: "Ken Morgan" <kemorgan at vt.edu>
To: mathgroup at smc.vnet.net
Subject: [mg44049]  two's complement function


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


  • Prev by Date: Re: Negation of Negation wanted
  • Next by Date: Re: Can someone tell me why NDsolve isn't working here?
  • Previous by thread: two's complement function
  • Next by thread: Re: two's complement function