Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
1992
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 1992

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

Search the Archive

number base conversion

  • To: mathgroup at yoda.physics.unc.edu
  • Subject: number base conversion
  • From: Stephen Wolfram <swolf>
  • Date: Fri, 27 Mar 1992 11:04:26 -0800

This converts a list of digits to an integer in the specified base:

FromDigits[list_List, base_:2] := Fold[#2 + base #1 &, 0, list]


There is an example of essentially this at the bottom of p. 202 of
my book (2nd ed.)

^^ was intended purely as a syntactic object.

In[1]:= FromDigits[list_List, base_:2] := Fold[#2 + base #1 &, 0, list]

In[2]:= FromDigits[{1, 1, 0, 1}]

Out[2]= 13

In[3]:= FromDigits[{15, 7, 10, 4}, 16]

Out[3]= 63396

In[4]:= IntegerDigits[%, 16]

Out[4]= {15, 7, 10, 4}

In[5]:= IntegerDigits[13, 2, 6]

Out[5]= {0, 0, 1, 1, 0, 1}






  • Prev by Date: [no subject]
  • Next by Date: Division of multi-var polynomials
  • Previous by thread: [no subject]
  • Next by thread: Division of multi-var polynomials