jbrave
14 years agoChannel Surfer
littleEndian > byteArray> signed integer and back
I'm reading a 16 bit little-endian file into a byte array and then converting it to signed 16bit integers:
function readcontroldata(ba as object)
for i=0 to ba.count()-1
int16=(ba+(ba[i+1]*256))-32768
...
next i
This appears to be correct, but I'm not 100% certain I"m getting the sign right, the file is stored as 2's-complement signed integers from -32768 to 32767. I think I've got the byte order correct, but the guesswork is, do I just assemble the two bytes into one 16bit word as above, or is there some other thing I need to do with the sign?
Now that I have successfully loaded the file I want to convert it back to 16 bit little -endian and write it back to tmp:/
I think I need to make it a positive 16 bit integer again before writing back to disk? I suppose I could just add 32768 to it to reverse the process, but not 100% sure of this.
There is no >> function in brightscript (I know there is in LIbRokuDev).
I think if I extract the low byte:
Lowbyte=int16 and &h00FF
and then:
highbyte=(int16-lowbyte)/256
Is that correct?
I realize LibRokuDev implements some of this, just trying to figure out how to do it myself.
Also, does anyone know how the signs are stored in a 16bit signed integer on Roku?
- Joel
function readcontroldata(ba as object)
for i=0 to ba.count()-1
int16=(ba+(ba[i+1]*256))-32768
...
next i
This appears to be correct, but I'm not 100% certain I"m getting the sign right, the file is stored as 2's-complement signed integers from -32768 to 32767. I think I've got the byte order correct, but the guesswork is, do I just assemble the two bytes into one 16bit word as above, or is there some other thing I need to do with the sign?
Now that I have successfully loaded the file I want to convert it back to 16 bit little -endian and write it back to tmp:/
I think I need to make it a positive 16 bit integer again before writing back to disk? I suppose I could just add 32768 to it to reverse the process, but not 100% sure of this.
There is no >> function in brightscript (I know there is in LIbRokuDev).
I think if I extract the low byte:
Lowbyte=int16 and &h00FF
and then:
highbyte=(int16-lowbyte)/256
Is that correct?
I realize LibRokuDev implements some of this, just trying to figure out how to do it myself.
Also, does anyone know how the signs are stored in a 16bit signed integer on Roku?
- Joel