MathGroup Archive 1996

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

Search the Archive

Re: Inverse of IntegerDigits? and "Index" function?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg3979] Re: Inverse of IntegerDigits? and "Index" function?
  • From: rhall2 at umbc.edu (hall robert)
  • Date: Mon, 13 May 1996 01:49:13 -0400
  • Organization: University of Maryland, Baltimore County
  • Sender: owner-wri-mathgroup at wolfram.com

In article <4menl1$jva at dragonfly.wolfram.com>,
 <pehowland at taz.dra.hmg.gb> wrote:

>I'm playing around with some binary numbers, and am using IntegerDigits
>to convert from a decimal integer to the binary notation.  eg.
>	In[1]:=	IntegerDigits[10,2]
>	Out[1]=	{1,0,1,0}
>
>What is the function to convert back? eg. I want to do
>	In[2]:=	DigitsToInteger[{1,0,1,0},2]
>and get
>	Out[2]= 10

In[57]:=
  changeBaseToTen[base_, powers_List] := Apply[
	Plus,
	powers Reverse[Map[base^#&, Range[Length[powers]] - 1]]
  ]

In[49]:=
  a = IntegerDigits[10, 2]
Out[49]=
  {1, 0, 1, 0}

In[50]:=
  changeBaseToTen[2, a]
Out[50]=
  10

>Thus I want a function that works as follows:
>
> 	In[3]:=	Map[Index[#]&, {2,6,3,9,10,2,4}]
>	Out[3]= {1,2,3,4,5,6,7}

In[51]:=
  Range[Length[{2,6,3,9,10,2,4}]]
Out[51]=
  {1, 2, 3, 4, 5, 6, 7}

-- 
Bob Hall            | "Know thyself? Absurd direction!
rhall2 at gl.umbc.edu  |  Bubbles bear no introspection."  -Khushhal Khan Khatak

==== [MESSAGE SEPARATOR] ====


  • Prev by Date: Kernel "Local" has lost connection
  • Next by Date: Re: Inverse of IntegerDigits? and "Index" function?
  • Previous by thread: Re: Inverse of IntegerDigits? and "Index" function?
  • Next by thread: Re: Inverse of IntegerDigits? and "Index" function?