hexadecimal and binary expressions/conversions



On 4/19/08, S. Newhouse <sen1 at math.msu.edu> wrote:

>   Does maxima have built in functions to do binary and/or hexadecimal
> conversions (in various precisions)?

The global variables ibase and obase control parsing and display of integers.

obase (output base) can be set to any value 2 through 35 inclusive.

You can set ibase to any value 2 through 35 inclusive, and ordinary
digits are interpreted in that base, but there is no way at present
to make Maxima recognize a, b, c, etc as digits.

I've attached a patch to make Maxima recognize a, b, c, ... as digits
when they are part of a number which begins with an ordinary digit.
When a, b, c ... are part of a token which begins with anything other
than an ordinary digit, they are not recognized as digits.
That prevents ibase from changing the meaning of Maxima symbols.

e.g.

(%i1) ibase : 16;
(%o1)                          16
(%i2) abc;
(%o2)                          abc
(%i3) symbolp (abc);
(%o3)                         true
(%i4) 0abc;
(%o4)                         2748
(%i5) symbolp (0abc);
(%o5)                         false
(%i6) 1abc;
(%o6)                         6844
(%i7) is (1abc = 1000 + 0abc);
(%o7)                         true
(%i8) ibase : 35.;
(%o8)                          35
(%i9) is (1000 = 35.^3.);
(%o9)                         true
(%i10) foobar;
(%o10)                       foobar
(%i11) 0foobar;
(%o11)                      824885977

Note the use of the trailing decimal point to indicate a literal
integer in base ten; this is a useful Lispism which Maxima inherits.

Maxima ibase is just an alias for *READ-BASE*; as such it should
allow 36 as a value. That's a separate (easily-fixed) bug.

FWIW

Robert Dodier
-------------- next part --------------
A non-text attachment was scrubbed...
Name: nparse.lisp-ibase-patch-2008-04-19
Type: application/octet-stream
Size: 1429 bytes
Desc: not available
Url : http://www.math.utexas.edu/pipermail/maxima/attachments/20080419/2fa35bc5/attachment.obj