B4J Question HEX value to float error

redarmy

New Member
hi,
In program, I direct put hex value to vars.
but "hex value to float " and "hex value to double" has err.
why can not put hex value to float ?

f32bit = 0x3F8CCCCD '1.1
Log("f32bit value: " & f32bit)
Log("f32bit Hex: " & bc1.HexFromBytes(bc1.FloatsToBytes(Array As Float(f32bit))))
but log message:
f32bit value: 1.066192064E9
f32bit Hex: 4E7E3333 -- not equal 0x3F8CCCCD

Log("f32bit value: " & 1.1)
Log("f32bit Hex: " & bc1.HexFromBytes(bc1.FloatsToBytes(Array As Float(1.1))))
f32bit value: 1.1
f32bit Hex: 3F8CCCCD -- This equal 1.1

program:
Sub Process_Globals
    Private fx As JFX
    Private MainForm As Form
    Private xui As XUI 
    Private Button1 As B4XView
    
    Dim i8bit As Byte
    Dim i16bit As Short
    Dim i32bit As Int
    Dim i64bit As Long
    Dim f32bit As Float
    Dim f64bit As Double
    
    Dim bc1 As ByteConverter
End Sub

Sub AppStart (Form1 As Form, Args() As String)
    MainForm = Form1
    MainForm.RootPane.LoadLayout("Layout1")
    MainForm.Show
    
    i8bit = 0x64
    Log("i8bit value: " & i8bit)
    Log("i8bit Hex: " & bc1.HexFromBytes(Array As Byte(i8bit)))
    
    i16bit = 0x2710
    Log("i16bit value: " & i16bit)
    Log("i16bit Hex: " & bc1.HexFromBytes(bc1.ShortsToBytes(Array As Short(i16bit))))
    
    i32bit = 0x3B9ACA00
    Log("i32bit value: " & i32bit)
    Log("i32bit Hex: " & bc1.HexFromBytes(bc1.IntsToBytes(Array As Int(i32bit))))
    
    i64bit = 0x6F05B59D3B200000 
    Log("i64bit value: " & i64bit)
    Log("i64bit Hex: " & bc1.HexFromBytes(bc1.LongsToBytes(Array As Long(i64bit))))
    
    f32bit = 0x3F8CCCCD '1.1
    Log("f32bit value: " & f32bit)
    Log("f32bit Hex: " & bc1.HexFromBytes(bc1.FloatsToBytes(Array As Float(f32bit))))
    Log("f32bit value: " & 1.1)
    Log("f32bit Hex: " & bc1.HexFromBytes(bc1.FloatsToBytes(Array As Float(1.1))))
    
    f64bit = 0x3FF199999999999A '1.1
    Log("f64bit value: " & f64bit)
    Log("f64bit Hex: " & bc1.HexFromBytes(bc1.DoublesToBytes(Array As Double(f64bit))))
    Log("f64bit value: " & 1.1)
    Log("f64bit Hex: " & bc1.HexFromBytes(bc1.DoublesToBytes(Array As Double(1.1))))
End Sub

log
Waiting for debugger to connect...
Program started.
i8bit value: 100
i8bit Hex: 64
i16bit value: 10000
i16bit Hex: 2710
i32bit value: 1000000000
i32bit Hex: 3B9ACA00
i64bit value: 8000000000000000000
i64bit Hex: 6F05B59D3B200000
f32bit value: 1.066192064E9
f32bit Hex: 4E7E3333
f32bit value: 1.1
f32bit Hex: 3F8CCCCD
f64bit value: 4.6076327787627546E18
f64bit Hex: 43CFF8CCCCCCCCCD
f64bit value: 1.1
f64bit Hex: 3FF199999999999A
libpng warning: iCCP: cHRM chunk does not match sRGB
 
Top