Message Boards Message Boards

1
|
8955 Views
|
2 Replies
|
4 Total Likes
View groups...
Share
Share this post:

The function (??) base^^

Posted 9 years ago

Hello,

The function base^^ (example 16^^1A2C or 2^^10112) always frustrates me because it seems to be a convenient function and it is a part of Mathematica but doesn't behave like other functions. For example Map[(16^^#)&, {A, B, D, F}] doesn't work. Also, FullForm[16^^A] returns 10. I don't know any other built in function to convert a base to base 10. Of course I can write my own conversion but base conversion is so common why can't there be a normal built in function for it? Further, why is base^^ such a pain in the rear?

Thanks.

POSTED BY: Roger B
2 Replies

^^ isn't a function. It's a syntax. Just as 2. means "the numeric version of 2" and not the integer, 16^^ab means "the number 171". This is handled by the parser, not the interpreter which is why FullForm[Hold[16^^A]] is Hold[10]. Howver, and as was said before, FromDigits is likely what you want.

POSTED BY: Jeremy Michelson
Posted 9 years ago

Hi,

The only function I know about that does what you are looking for is FromDigits. For example

Map[FromDigits[#, 16] &, {"a", "b", "d", "f", "1A2C"}]

I do not know why the function ^^ does not work in your Map example. I would be also interested in reading the reason.

POSTED BY: Xavier Roy
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract