MathGroup Archive 2007

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

Search the Archive

Re: Converting Binary form to a desired array



Hi,

I would do it like this

ToBinary[number_Integer] := ToBinary[IntegerDigits[number, 2]];
ToBinary[{b_}] = {b};
ToBinary[{b_, rest___}] := Prepend[ToBinary[{rest}], 2^Length[{rest}]*b];


ToBinary[212] = {128, 64, 0, 16, 0, 4, 0, 0}

Cheers
Patrick


Am 14.05.2007, 09:45 Uhr, schrieb athlonspell <athlonspell at yahoo.ca>:

> 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



-- 
Erstellt mit Operas revolutionärem E-Mail-Modul: http://www.opera.com/mail/


  • Prev by Date: Re: How to get sqrt(Year^2)===Year?
  • Next by Date: Re: Package Help in Mathematica 6
  • Previous by thread: Converting Binary form to a desired array
  • Next by thread: Re: Converting Binary form to a desired array