Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

Decimal! to Binary! conversion

 [1/2] from: oliva:david:seznam:cz at: 15-Jan-2002 19:17


Decimal! to Binary! conversion ============================== Hello rebolers... does anybody know how to convert decimal number to binary format? In Flash it's stored as: 0.1 = #{9999B93F9A999999} 0.2 = #{9999C93F9A999999} 0.5 = #{0000E03F00000000} 1.5 = #{0000F83F00000000} That gives me no sense... please help me:-) thanks Oldes

 [2/2] from: larry::ecotope::com at: 15-Jan-2002 14:02


Hi Oldes, You can find some conversion routines for binary to REBOL decimal in decimal.r. http://www.nwlink.com/~ecotope1/reb/decimal.r There are two formats: big-endian and little-endian. The little-endian (least significant bits first in memory) is the Intel standard. The routines allow you to reverse the bytes, if necessary. If you don't know the endian convention, just try it with and without reverse on a sample number. Some examples:
>> real/to-native/rev 0.1
== #{9A9999999999B93F}
>> real/to-native/rev 0.2
== #{9A9999999999C93F}
>> real/to-native/rev 0.5
== #{000000000000E03F}
>> real/to-native/rev 1.5
== #{000000000000F83F} It appears the flash format puts the last 4 bytes first and vice versa. So you might need to make this change to flash format numbers before using real/form-native/rev. HTH -Larry