MathGroup Archive 2007

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

Search the Archive

Re: Converting Binary form to a desired array


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


  • Prev by Date: Re: Picking out pieces of a list
  • Next by Date: Re: Mathematica 6.0 - Legend
  • Previous by thread: Re: Converting Binary form to a desired array
  • Next by thread: Re: Converting Binary form to a desired array