       Re: Converting table to a number?

• To: mathgroup at smc.vnet.net
• Subject: [mg2112] Re: Converting table to a number?
• From: villegas (Robert Villegas)
• Date: Wed, 4 Oct 1995 01:52:46 -0400
• Organization: Wolfram Research, Inc.

```> I have a list of numbers, such as this:
>
>         { 1, 0, 1, 1, 0, 1, 0, 0 }
>
> and I want to convert it into this:
>
>         10110100 (binary)

If you just want something to display as the binary sequence, you can
join the digits into a string:

In:= StringJoin[ToString /@ { 1, 0, 1, 1, 0, 1, 0, 0 }]

Out= 10110100

or use a formatting function that displays its elements in a horizontal
sequence:

In:= SequenceForm @@ { 1, 0, 1, 1, 0, 1, 0, 0 }

Out= 10110100

If you want to form the actual integer, you can use the ^^ operator:

In:= 2^^10110100

Out= 180

Here's a function that makes it easy to convert a base and a string or list
of digits to the represented integer:

-----------------------------------------------------------------------------
BasePower[base_, digits_String] := ToExpression[ToString[base] <> "^^" <>
digits]

BasePower[base_, digits:{__String}] := BasePower[base, StringJoin[digits]]

\$letters = FromCharacterCode /@ Range[64 + 1, 64 + 26]

\$todigits = Thread[Range[10, 35] -> \$letters]

BasePower[base_, digits:{__Integer}] :=
BasePower[base, ToString /@ (digits /. Thread[Range[10, 35] -> \$letters]) ]
-----------------------------------------------------------------------------

It works up to base 36.  You can give digits as actual integers, or as
letters:

In:= BasePower[16, {13, 12, 11}]

Out= 3531

In:= BasePower[16, "DCB"]

Out= 3531

In:= BasePower[16, {"D", "C", "B"}]

Out= 3531

Robby Villegas

```

• Prev by Date: Re: Best Windows for Mma 2.2.2????
• Next by Date: mathematica syntax, matrix notation
• Previous by thread: Re: Converting table to a number?
• Next by thread: Simplifying vector expressions