Re: Converting Integer to Binary and using bits
- To: mathgroup at smc.vnet.net
- Subject: [mg29401] Re: [mg29391] Converting Integer to Binary and using bits
- From: BobHanlon at aol.com
- Date: Sat, 16 Jun 2001 22:43:50 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
In a message dated 2001/6/16 2:53:20 AM, Flip at safebunch.com writes: >I know that there is BaseForm[a,b] to convert between bases, but I need >some >more functionality. > >I need to be able to convert a large integer (300 - 600 digits) long to >binary, >know the number of digits (for a looping variable) and then use each individual >bit (from high bit to low bit). > >For example, n = 11, so 11 base 10 = 1011 base 2. > >The length = 4. > >With the for loop, a test of each bit will be done (in this example 1, >0, 1, 1). > >Can someone give any direction on how to do this? id = IntegerDigits[11, 2] {1, 0, 1, 1} Length[id] 4 If possible, avoid use of a looping variable and act on the list. For example, f /@ id {f[1], f[0], f[1], f[1]} f[x, #]& /@ id {f[x, 1], f[x, 0], f[x, 1], f[x, 1]} Bob Hanlon Chantilly, VA USA