MathGroup Archive 2007

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

Search the Archive

Re: Converting Binary form to a desired array


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