Is there a really clever way to do this, or is the only way to do it the hard way?
Edit: I need to read a signed short in big-endian format.
Does anyone have a way of doing this easilly, or will I have to convert to little-endian and then convert to unsigned.
Andy
To swap the endian of a signed, 2byte short, I think you simply swap the byte order, like so:
((n And $00FF) Shl 8) Or ((n And $FF00) Shr 8)
You must also adjust by 65536 to simulate a signed 16-bit value.
Print ConvertSignedShort( $0200 )
Print ConvertSignedShort( $0100 )
Print ConvertSignedShort( $0000 )
Print ConvertSignedShort( $FFFF )
Print ConvertSignedShort( $FEFF )
WaitKey
Function ConvertSignedShort( ss ) ; bottom two bytes of an Int.
ss = ( ( ss And $ff00 ) Shr 8 ) Or ( ( ss And $ff ) Shl 8 )
If ss < $8000
Return ss
Else
Return ss - $10000
End If
End Function
big10p and Floyd,
Thanks, you guys rock! It works perfectly!
Andy