Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I want to transform a list of binary digits into integers. With the Table function, I produce four lists of binary digits of length 32. Then I tried to turn these lists into integers, but it didn't work. Any suggestions?

Table[b[i] = 1, {i, 0, 32}];
Table[b[k] = b[i + j] = Mod[(b[i + j - 5] + b[i + j - 32]), 2], {i, 32, 35}, {j, 0, 31}]
FromDigits[{b[k]}, 2]
share|improve this question
add comment

2 Answers

Using more or less your approach, I use RandomChoice to create some "binary numbers". Next you can use FromDigits and map it on this list.

FromDigits[#, 2] & /@ RandomChoice[{0, 1}, {4, 32}]

Edit: I assumed these "binary" numbers to be random. If you want to use it for the numbers you created, just map it on those. My RandomChoice produces numbers of the same format.

share|improve this answer
    
Thanks, it works! –  user5484 Jan 21 '13 at 12:55
    
great - you are welcome. And make sure you understand Map (or just /@) well, that's very useful –  Pinguin Dirk Jan 21 '13 at 13:01
2  
Just for fun. FromDigits[#, 2] & /@ randomChoice == (Fold[ 2 #1 + #2 &, 0, #] & /@ randomChoice) –  TomD Jan 21 '13 at 17:37
    
@TomD - nice one, it took a bit for me to understand the syntax... –  Pinguin Dirk Jan 21 '13 at 18:25
add comment

You can use

BaseForm[number, base]

and just run every number through the command.

Example:
BaseForm[2^^1101101,2]
share|improve this answer
1  
What if I have 10000 numbers? –  user5484 Jan 21 '13 at 12:37
    
@user5484 You would then use Map or it's shortform /@. –  image_doctor Jan 21 '13 at 13:03
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.