Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2006
*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 2006

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

Search the Archive

Re: Code to translate to negative base...

  • To: mathgroup at smc.vnet.net
  • Subject: [mg64543] Re: Code to translate to negative base...
  • From: Paul Abbott <paul at physics.uwa.edu.au>
  • Date: Wed, 22 Feb 2006 05:58:26 -0500 (EST)
  • Organization: The University of Western Australia
  • References: <dte2au$rie$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

In article <dte2au$rie$1 at smc.vnet.net>,
 Richard Palmer <mapsinc at bellatlantic.net> wrote:

> ... Does anyone have code to translate to a negative base?  Ideally the code
> would work like RealDigits; except that the second argument (base) could be
> negative.

See 
 
  http://library.wolfram.com/conferences/devconf99/challenge/winners.nb

for extension of IntegerDigits to base -2. Extension to negative integer 
base is straightforward:

  integerDigits[0, n_Integer /; n < 0] := {0}

  integerDigits[i_, n_Integer /; n < 0] := Rest @ Reverse @ 
     Mod[NestWhileList[(# - Mod[#, -n])/n & , i, # != 0 & ], -n]

Now, you just need to extend this to handle real numbers ...

Cheers,
Paul

_______________________________________________________________________
Paul Abbott                                      Phone:  61 8 6488 2734
School of Physics, M013                            Fax: +61 8 6488 1014
The University of Western Australia         (CRICOS Provider No 00126G)    
AUSTRALIA                               http://physics.uwa.edu.au/~paul


  • Prev by Date: Re: question about Split[...]
  • Next by Date: Re: Re: Greek-Letter Bug? Replacing Print
  • Previous by thread: Code to translate to negative base...
  • Next by thread: Re: Code to translate to negative base...