Page 1 of 1

problem with ReadByte() function

Posted: Sat May 03, 2003 10:36 am
by patrick88
if you would read a value superior at 127, the function ReadByte()
take a négative value . 8O
for example reading 128 take -128, cool :(
my solution :

Code: Select all

octet = ReadByte()
If octet<0
   octet = 128+(128+octet)
EndIf
enjoy

Posted: Sat May 03, 2003 11:07 am
by GPI
No bug or something like this.

Bytes are signed, so they have a range from -128 to 127

to convert them to 0 to 256, simple use this

b.b=-100
l.l=b&$ff

Posted: Sun May 04, 2003 7:38 pm
by Danilo

Code: Select all

octet = ReadByte() & $FF
Thats exactly what patrick88 wanted to say :D

Posted: Sun May 04, 2003 7:52 pm
by GPI
Danilo wrote:

Code: Select all

octet = ReadByte() & $FF
Thats exactly what patrick88 wanted to say :D
No it isn't.
and & operation is shorter to write and should be faster than an if and add.

Posted: Sun May 04, 2003 9:44 pm
by Danilo
You dont get it, GPI - as always... :roll:

Posted: Sun May 04, 2003 11:16 pm
by GPI
Yes i like you too.