Re: Converting Binary form to a desired array
- To: mathgroup at smc.vnet.net
- Subject: [mg76040] Re: [mg75980] Converting Binary form to a desired array
- From: János <janos.lobb at yale.edu>
- Date: Tue, 15 May 2007 04:54:07 -0400 (EDT)
- References: <200705140745.DAA23104@smc.vnet.net>
On May 14, 2007, at 3:45 AM, 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 Here is a newbie approach: In[20]:= ones = Most[ToExpression /@ Characters[StringTake[ ToString[BaseForm[212, 2]], StringPosition[ ToString[BaseForm[ 212, 2]], "\n"][[1, 1]]]]] Out[20]= {1, 1, 0, 1, 0, 1, 0, 0} In[82]:= First[Last[Reap[ l = Length[ones]; For[i = 1, i <= l, i++, If[ones[[i]] == 0, Sow[ones[[i]]], j = l - i; Sow[ 2^HoldForm[Evaluate[ j]]]]]]]] Out[82]= {2^HoldForm[7], 2^HoldForm[6], 0, 2^HoldForm[4], 0, 2^HoldForm[2], 0, 0} In[92]:= $Version Out[92]= "5.2 for Mac OS X (64 bit) \ (June 20, 2005)" J=E1nos ---------------------------------------------- Trying to argue with a politician is like lifting up the head of a corpse. (S. Lem: His Master Voice)
- References:
- Converting Binary form to a desired array
- From: athlonspell <athlonspell@yahoo.ca>
- Converting Binary form to a desired array