# "A number in base b" and pure functions: why doesn't b^^# & work?

Why do the following not work (in Mathematica 7)?

2^^ # & /@ {1000, 1101}


and

2^^ # & @ 1101


This does work:

2^^1101


giving, as expected:

(*13*)


(This also works:

BaseForm[#, 2] & /@ {13, 14}


)

See here for further information ("Digits in numbers")

• Note that 2^^ 1101 doesn't work either, which already is a strong hint that one shouldn't expect 2^^ # & to work. May 24, 2012 at 12:12
• I like how in MMA questions can appear to be censored curse words. What the F^^@@#? May 24, 2012 at 13:24

The reason is that the notation base^^digits is interpreted at parsing time, not evaluation time. I explained the difference in this answer.

You can use FromDigits instead:

fromBaseTwo = FromDigits[#, 2]&

fromBaseTwo["10011"]


Note that I used a string as input. FromDigits works both with strings and lists of digits.

• I feel that this previous question says it all. Vote to close this one? May 24, 2012 at 11:13
• @Sjoerd Personally I'm fine with closing. Maybe the FromDigits part (how to actually construct that pure function) is a worthwhile addition here? May 24, 2012 at 11:16
• Didn't we cover that here? May 24, 2012 at 11:49
• @Sjoerd I did consider voting to close briefly, before posting an answer, but for some reason I didn't. Just do what you feel is correct :-) May 24, 2012 at 14:26
• I wish I could just vote to close without casting a super close vote. I'm hesitating because of this pure function part in the question, but actually it doesn't make much of a difference. May 24, 2012 at 14:36

Here is a somewhat messed-up way to do something like what you wanted to do:

ToExpression["2^^" <> ToString[#]] & /@ {1000, 1101}
{8, 13}