[REBOL] Re: Converting numbers to binary form.
From: g:santilli:tiscalinet:it at: 9-Sep-2002 21:42
Hi Alan,
On Monday, September 9, 2002, 5:24:57 PM, you wrote:
ap> Is there an easy way to represent numbers in their binary form?
This is the easy way, provided you're on a little-endian platform:
>> s: make struct! [num [integer!]] [0]
>> integer-to-binary: func [i [integer!]] [s/num: i head reverse third s]
>> integer-to-binary 100
== #{00000064}
>> integer-to-binary 100000000
== #{05F5E100}
On big-endian platforms you just don't need to REVERSE it.
A (probably slower, but didn't test it) multiplatform way is:
>> integer-to-binary: func [i [integer!]] [debase/base to-hex i 16]
>> integer-to-binary 100000000
== #{05F5E100}
Regards,
Gabriele.
--
Gabriele Santilli <[g--santilli--tiscalinet--it]> -- REBOL Programmer
Amigan -- AGI L'Aquila -- REB: http://web.tiscali.it/rebol/index.r