B4R Question To and from 32bit float

peacemaker

Expert
Licensed User
Longtime User
SOLVED:
B4X:
'the digit is devided to the devider
Sub FourBytesTo32bitFloat(FourBytes() As Byte, Divider As UInt) As Float
    Dim Swapped(4) As Byte
    Swapped(0) = FourBytes(1)
    Swapped(1) = FourBytes(0)
    Swapped(2) = FourBytes(3)
    Swapped(3) = FourBytes(2)
    Dim b(4) As Byte
    Dim bc as ByteConverter
    bc.ArrayCopy2(Swapped, 0, b, 0, 4)
    Dim d() As Double = bc.DoublesFromBytes(b)
    Dim res As Float = d(0) / Divider
    Return res
End Sub
 
Last edited:
Upvote 0

peacemaker

Expert
Licensed User
Longtime User
p.s. @emexes is really right that ByteConverter has .LittleEndian flag, Swapping bytes is not needed for B4A, B4J, B4i.
But not for B4R.
 
Last edited:
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…