# Splitting a binary number into smaller parts and converting each smaller part back to decimal

This is my first Mathematica post and I would be obliged if you could be patient with me.

I have the following large binary number $1111010010001001100011010101111110000101101110110011100101$ which I have split into 4 smaller parts.

$1111\ 01001000100110001101010\ 111111\ 0000101101110110011100101$

How would I convert each of the 4 smaller parts back into decimal values i.e 1111 is the same as 15 etc.

I used IntegerString to convert the number to binary and StringTake to break the binary number down into the smaller groups and now I am stuck.

• Aug 1 '18 at 11:54
• S.Cook, could you clarify if the input is a String ("1111 01001000100110001101010 111111 0000101101110110011100101") or a list of Integers (1111, 01001000100110001101010, 111111, 0000101101110110011100101})?
– kglr
Aug 1 '18 at 12:03
• It was a string. Aug 2 '18 at 17:01

d = {1111, 01001000100110001101010, 111111, 0000101101110110011100101};
FromDigits[#, 2] & /@ IntegerDigits@d


{15, 2378858, 63, 1502437}

string = "1111 01001000100110001101010 111111 0000101101110110011100101";

FromDigits[#, 2] & /@ StringSplit[string]


{15, 2378858, 63, 1502437}

Update: To work directly with with original string:

sPartition = FromDigits[#, 2] & /@ StringJoin /@ TakeList[Characters @ #, #2]&;

string0 = "1111010010001001100011010101111110000101101110110011100101";
sPartition[string0, {4, 23, 6, All}]


{15, 2378858, 63, 1502437}

Update 2: The answer above assumes the input is a String. If, instead, it is a list of Integers, then, in addition to the methods in other answers you can also do

#. (2)^(# - Range @ # & @ Length @ #) & /@
IntegerDigits[{1111, 01001000100110001101010, 111111, 0000101101110110011100101}]


{15, 2378858, 63, 1502437}

• your last update does not work as expected. Aug 1 '18 at 13:09
• @OkkesDulgerci, make sure you have space between Dot (.) and 2 so that you are not multiplying # with .2.
– kglr
Aug 1 '18 at 13:13
• Interesting. When I pasted the space is disparaged Aug 1 '18 at 13:21
FromDigits[#, 2] & /@ (ToString /@ d)


where d = {1111, 01001000100110001101010, 111111, 0000101101110110011100101}

Fold[2 #1 + #2 &, 0, #] & /@ (IntegerDigits@d)


{15, 2378858, 63, 1502437}

where

d = {1111, 01001000100110001101010, 111111, 0000101101110110011100101};