float nach binary...
Verfasst: Montag 7. Juli 2014, 17:13
Dinge die die welt nicht braucht
Bei meinem Emulator ist irgendwo in der nähe der Floating point Routinen des BASIC Interpreter ein bug.
Basic speichert Float Zahlen so:
Ist anscheinend das selbe wie bei C64, siehe: http://www.c64-wiki.com/index.php/Float ... arithmetic
Nun möchte ich gern in Python eine Zahl zu dieser Speicherart konvertieren und damit rumtesten.
Als ersten Anhaltspunkt habe ich das zusammen:
Ausgabe:
Hilft aber irgendwie nicht weiter, weil es nicht das richtige Format ist.

Bei meinem Emulator ist irgendwo in der nähe der Floating point Routinen des BASIC Interpreter ein bug.
Basic speichert Float Zahlen so:
Somit entspricht es wohl nicht dem IEEE 754 binary32 Standard.exponent: 1Byte = 8 Bits (most significant bit is the sign 1=positive 0=negative)
mantissa/fraction: 4Bytes = 32 Bits
sign of mantissa: 1Byte = 8 Bits (0x00 positive, 0xff negative)
Ist anscheinend das selbe wie bei C64, siehe: http://www.c64-wiki.com/index.php/Float ... arithmetic
Nun möchte ich gern in Python eine Zahl zu dieser Speicherart konvertieren und damit rumtesten.
Als ersten Anhaltspunkt habe ich das zusammen:
Code: Alles auswählen
import struct
def convert(value):
return struct.unpack('>l', struct.pack('>f', value))[0]
def test(value):
print "***", value
converted = convert(value)
print "converted:", converted
print "binary: {0:08b}".format(converted)
test(5.5)
test(-5.5)
Code: Alles auswählen
*** 5.5
converted: 1085276160
binary: 1000000101100000000000000000000
*** -5.5
converted: -1062207488
binary: -111111010100000000000000000000