RE: Types... Slate -> C -> Slate conversión
Paul Dufresne
dufrp at hotmail.com
Wed Oct 13 18:13:05 PDT 2004
>But then, how do I convert between ByteArrays to those things and back
>(sorry,
>I don't remember much of my digital lessons, so, managing signed and
>unsigned
>numbers is not easy for me).
You didn't told if you want to convert in Slate or in C.
Anyway, here is the basic idea:
if the highest bit is 1, then number is negative, to know the number
you change all the bits to the other value by doing the value xor (exclusive
or)
the value, then you add 1.
An other way, around this, for converting two bytes SInt16, to UInt16
value = 256 * byte[0] + byte[1] ' this concatenates the 2 bytes
if value < 0
then value = - (65536 - value)
65536 is 1 more than all the bits to 1.
or maybe this is value= 256 * byte[1] + byte[0] (I am confused a bit)
I don't know if this is what you wanted to know.
--Paul (hoping to help more than I am confusing)
More information about the Slate
mailing list