Hi!
I have a incoming UDP package that contains 4 Byte variables. I want to combine them into a single precision floating point value. howto?
I also need to convert a single precision floating point into 4 bytes.
The PowerBasic CVS and MKI$ functions?
How are you storing the 4 bytes? in a string or byte array? You can use a UNION TYPE or a pointer to recast the data. For example.
UNION FourBytesOfFunType
s AS STRING * 4
a(1 TO 4) AS BYTE
r AS SINGLE
END UNION
DIM FourBytesOfFun AS FourBytesOfFunType
receive data into FourBytesOfFun.s or FourBytesOfFun.a() and then process as FourBytesOfFun.r
or:
'Holds 4 bytes of data
LOCAL sData AS STRING
DIM bData( 1 TO 4) AS BYTE
LOCAL prData AS SINGLE PTR
LOCAL rData AS SINGLE
prData = STRPTR( sData)
or
prData = VARPTR( bData(1))
rData = @prData