Short INT / Unsigned Short INT

Blitz3D Forums/Blitz3D Beginners Area/Short INT / Unsigned Short INT

Sarakan(Posted 2004) [#1]
Please tell me there's already a way to convert between a SHORT and an UNSIGNED SHORT in blitz.


An INT (32bits/4bytes) is -2147483648 to 2147483647
A unsigned INT (32bits) is 0 to 4294967295
A SHORT INT (16bits/2bytes) is -32128 to 32127
A unsigned SHORT INT (16bit) is 0 to 65535
A Char (8bit/1byte) is -128 to 127
A unsigned Char (8bit/1byte also called an Octet) is 0 to 255



soja(Posted 2004) [#2]
Well, it's really a moot issue since Blitz doesn't have a SHORT type. Only dealing with (a) banks, and (b) userlibs do you really end up dealing with shorts, and in both cases, it's just 16 bits of data to Blitz. Whether it's signed or unsigned depends on the consumer -- either you (banks) or the DLL (userlibs) -- but it's the same data either way.

Does that make sense (and answer your question)?


Floyd(Posted 2004) [#3]
I assume this means you have a 16-bit value stored in a Blitz 32-bit integer, with the high 16 bits all being zero.

Blitz will see this as unsigned: 0 to 65535.

To convert to signed you leave 0 to 32767 unchanged.
For values greater than 32767 you must subtract 65536.

Example: n% = %111111111111111 ( sixteen ones ).

This is 65535 unsigned, but is 65535-65536 = -1 signed.