Message Boards Message Boards

5 Replies
3 Total Likes
View groups...
Share this post:

Converting BaseForm Result into a Usable Integer for Computation

Posted 9 years ago

I am trying to do the following:

theMin = BaseForm[16^^1000,10]
theMax = BaseForm[16^^10000,10]

However this results in an error because Head[theMin] is BaseForm. How can I convert "theMin" and "theMax" from the "display BaseForm" formats into an integer format that can be used for computation?

What I want to get is the following

POSTED BY: Bob Stephens
5 Replies
Posted 9 years ago

Bruce, thanks that is great - I did not know you could do the assignment inside the Form function. It would be nice if Mathematica added a parameter/property to the built-in Head function that allowed the user to specify the desired format for a variable and then the return value of the Head function could be a list of recommended options (or function paths) to get to that result. I know that sounds like a complicated (and crazy) request but it would be a slick option.

@John, thanks for providing the alternative unwrap method as well.

POSTED BY: Bob Stephens

What are you really trying to do, anyway? Why use BaseForm to display base 10, when base 10 is the default?

POSTED BY: John Doty

Unwrap before numericizing:

In[93]:= 20*Log10[theMax/theMin] /. BaseForm[x_, _] -> x // N

Out[93]= 24.0824
POSTED BY: John Doty

This question comes up with TableForm and MatrixForm a lot. The solution is to do the assignment inside the *Form function.

In[1]:= BaseForm[theMin = 16^^1000, 10]

In[2]:= theMin
Out[2]= 4096

In[3]:= Head[theMin]
Out[3]= Integer

Usually, the content of the *Form wrapper can be extracted with First.

In[5]:= aMin = BaseForm[16^^1000, 10]

In[6]:= First[aMin]
Out[6]= 4096
POSTED BY: Bruce Miller
Posted 9 years ago

Actually this worked........

theMin2 = FromDigits["1000",16]
theMax2 = FromDigits["10000",16]


It would be nice if it were possible to wrap a built-in function around BaseForm to be able to reuse the BaseForm variables in other calculations

POSTED BY: Bob Stephens
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
or Discard

Group Abstract Group Abstract