MathGroup Archive 2007

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

Search the Archive

Re: Converting Binary form to a desired array

  • To: mathgroup at smc.vnet.net
  • Subject: [mg76148] Re: Converting Binary form to a desired array
  • From: Szabolcs <szhorvat at gmail.com>
  • Date: Wed, 16 May 2007 05:56:03 -0400 (EDT)
  • Organization: University of Bergen
  • References: <f2959d$n0n$1@smc.vnet.net> <f29bml$pku$1@smc.vnet.net>

Szabolcs wrote:
> athlonspell wrote:
>> Hello,
>>
>> I have this:
>>
>>>  BaseForm[212,2] = 10100 
>> Now, I am trying to achieve this output from above:
>>
>>>  {2^4, 0, 2^2, 0, 0}
>> How do I go about do this? 
>>
>> Thank you,
>> Sharon
>>
> 
> Reverse@MapIndexed[#1 Superscript[2, First@#2] &,
>    Reverse@IntegerDigits[212, 2]]
> 
> You may want to replace Superscript by Power if you need usable numbers 
> in the list (but then 8 will be displayed instead of 2^3).
> 

Sorry, this should be

Reverse@MapIndexed[#1 Superscript[2, First@#2-1] &,
    Reverse@IntegerDigits[212, 2]]

(note the -1 in the second argument of Superscript)


  • Prev by Date: Re: Where is the Mathematica Book in Documentation Center?
  • Next by Date: Re: Residue Function
  • Previous by thread: Re: Converting Binary form to a desired array
  • Next by thread: HoldForm