
Code : Tout sélectionner
a.f = Pow(2, 32)
Debug a
Debug a - 1.0
Debug a + 1.0
Code : Tout sélectionner
a.f = Pow(2, 32)
Debug a
Debug a - 1.0
Debug a + 1.0
Code : Tout sélectionner
Procedure.s ByteToBin(b.b)
Protected s.s, i.b, pow.b
s = "00000000"
For i = 0 To 7
pow = Pow(2,i)
If b & pow
PokeB(@s + (7-i), Asc("1"))
EndIf
Next
;Debug s
ProcedureReturn s
EndProcedure
Procedure.s LongToBin(l.l)
Protected s.s, i.w, pow.l
s = "00000000000000000000000000000000"
For i = 0 To 31
pow = Pow(2,i)
If l & pow
PokeB(@s + (31-i), Asc("1"))
EndIf
Next
;Debug s
ProcedureReturn s
EndProcedure
;a.f = Pow(2, 32)
;Debug a
a.l = 32767
Debug "Conversion de " + Str(a)
s.s
For i = 0 To 3
s = ByteToBin(PeekB(@a + i)) + s
Next i
Debug s
Debug LongToBin(a)
; ***********************
; * Partie Float !!! *
; ***********************
; -------------------------- BUG !!! ------------------------
Debug " --- "
b.f = Pow(2,32)
Debug b
s = ""
For i = 0 To 3
s = ByteToBin(PeekB(@b + i)) + s
Next i
Debug s
b.f = -13.125
Debug b
s = ""
For i = 0 To 3
s = ByteToBin(PeekB(@b + i)) + s
Next i
Debug s
b.f = 1
Debug b
s = ""
For i = 0 To 3
s = ByteToBin(PeekB(@b + i)) + s
Next i
Debug s
b.f = -1
Debug b
s = ""
For i = 0 To 3
s = ByteToBin(PeekB(@b + i)) + s
Next i
Debug s
Code : Tout sélectionner
*ptr.Long = @var.f
var = Pow(2, 32)
Debug Bin(*ptr\l)
Code : Tout sélectionner
Procedure.s Debug_Float32(Address.f)
Sign.l = PeekL(@Address) & $80000000
If Sign : Sign = -1 : Else : Sign = 1 : EndIf
Exponant.l = PeekL(@Address) & $07F80000
Exponant.l = Exponant >> 23
Mantissa.l = PeekL(@Address) & $007FFFFF
Mantissa_Copy.l = Mantissa
ProcedureReturn RSet(Hex(PeekL(@Address)), 8, "0") + " Sign : " + Str(Sign) + " Exponant : " + RSet(Hex(Exponant), 2, "0") + " Mantissa : " + RSet(Hex(Mantissa), 6, "0")
EndProcedure
fValue.f
fValue = 0.0 : Debug StrF(fValue, 10) + " " + Debug_Float32(fValue)
fValue = 1.0 : Debug StrF(fValue, 10) + " " + Debug_Float32(fValue)
fValue = 2.0 : Debug StrF(fValue, 10) + " " + Debug_Float32(fValue)
fValue = 3.14159265 : Debug StrF(fValue, 10) + " " + Debug_Float32(fValue)
fValue = -3.14159265 : Debug StrF(fValue, 10) + " " + Debug_Float32(fValue)
fValue = 31.4159265 : Debug StrF(fValue, 10) + " " + Debug_Float32(fValue)
fValue = 31415.9265 : Debug StrF(fValue, 10) + " " + Debug_Float32(fValue)
End
Code : Tout sélectionner
Procedure.s FloatToBin(Address.f)
Protected Exponant.l, Mantissa.l, s.s, i.b, pow.l
s = "00000000000000000000000000000000"
If PeekL(@Address) & $80000000
PokeB(@s, Asc("1"))
EndIf
Exponant.l = PeekL(@Address) & $07F80000
Exponant.l = Exponant >> 23
For i = 0 To 7
pow = Pow(2,i)
If Exponant & pow
PokeB(@s + (8-i), Asc("1"))
EndIf
Next
Mantissa.l = PeekL(@Address) & $007FFFFF
For i = 0 To 20
pow = Pow(2,i)
If Mantissa & pow
PokeB(@s + (31-i), Asc("1"))
EndIf
Next
ProcedureReturn s
EndProcedure
Code : Tout sélectionner
Procedure.s ByteToBin(b.b)
Protected s.s, i.b, pow.b
s = "00000000"
For i = 0 To 7
pow = Pow(2,i)
If b & pow
PokeB(@s + (7-i), Asc("1"))
EndIf
Next
;Debug s
ProcedureReturn s
EndProcedure
Procedure.s LongToBin(l.l)
Protected s.s, i.w, pow.l
s = "00000000000000000000000000000000"
For i = 0 To 31
pow = Pow(2,i)
If l & pow
PokeB(@s + (31-i), Asc("1"))
EndIf
Next
;Debug s
ProcedureReturn s
EndProcedure
Procedure.s FloatToBin(f.f)
ProcedureReturn LongToBin(PeekL(@f))
EndProcedure