Binary hex representation in mathematica and python
You can use ord and hex like this: Anyway, the program seems to work, but the algorithm s can probably be improved.
After reading the discussion, I took into account the suggestion that the program should perform conversions from any base to any other base. The binary to number conversion is easy because it's supported by Racket. Racket only supports the number to binary conversion for integer numbers, so we multiply the original number by a power of two, to get all the binary digits, and then we manipulate the string to place the point in the correct place.
Bases up to 62 will just use decimal digits along with upper and lowercase Latin letters. This REXX program is a modified version of the original program which can handle any base no limit , and the original program did more extensive error checking. Bases that are negative are also supported which won't be explained here.
By far the easiest way to do this is to use Tcl's built-in handling of IEEE arithmetic, converting the IEEE representation into the string representation we want and vice versa by simple string manipulations.
Adapting the code to work with IEEE double-precision floats is left as an exercise for the reader, as is dealing with the trickier special cases of the infinities and NaN. Create account Log in. Page Discussion Edit History. Decimal floating point number to binary From Rosetta Code. Decimal floating point number to binary is a draft programming task.