Notifications
Clear all

[Closed] 4 bytes to Float ?

Hi, i am trying to read serial interface with max script, the problem is that i need a floating point value. How to convert 4 bytes integers to Float ?

thanks in advance

edit :
solution for integers to float is simple bit[font=Courier New].intAsFloat <integer>[/font]
but the things are a lot worst in reality. I discover that my new problem is to get big to little endian convertion with max script seems like its a mission imposible for me.

edit2 :
Seems like other people already had headache with binary files

fn ShortSwap s = (
b1 = bit.and s 255
b2 = bit.and (bit.shift s 8) 255
return ( (bit.shift 8 b1) + b2 )
)

so any idea how to do LONGSWAP fn… i am realy bad wit the math

2 Replies

Big to Little indean values convertion
And this is final result, if somebody needs, here it is

 
--Big to Little indean convertion--- 
 
fn SwapShort short = bit.swapBytes short 1 2


fn SwapLong long =(
long = bit.swapBytes long 1 4
long = bit.swapBytes long 2 3
)

Sorry to bring up this post but could someone post an example of reading a float with the code provided here.
something along the lines of
vx = readfloat f
only ow would I change this to add the swapfloat function?