problem with ReadByte() function

Share your advanced PureBasic knowledge/code with the community.
patrick88
User
User
Posts: 18
Joined: Sat May 03, 2003 10:30 am

problem with ReadByte() function

Post 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
a+

pat
GPI
PureBasic Expert
PureBasic Expert
Posts: 1394
Joined: Fri Apr 25, 2003 6:41 pm

Post 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
User avatar
Danilo
Addict
Addict
Posts: 3036
Joined: Sat Apr 26, 2003 8:26 am
Location: Planet Earth

Post by Danilo »

Code: Select all

octet = ReadByte() & $FF
Thats exactly what patrick88 wanted to say :D
cya,
...Danilo
...:-=< http://codedan.net/work >=-:...
-= FaceBook.com/DaniloKrahn =-
GPI
PureBasic Expert
PureBasic Expert
Posts: 1394
Joined: Fri Apr 25, 2003 6:41 pm

Post 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.
User avatar
Danilo
Addict
Addict
Posts: 3036
Joined: Sat Apr 26, 2003 8:26 am
Location: Planet Earth

Post by Danilo »

You dont get it, GPI - as always... :roll:
cya,
...Danilo
...:-=< http://codedan.net/work >=-:...
-= FaceBook.com/DaniloKrahn =-
GPI
PureBasic Expert
PureBasic Expert
Posts: 1394
Joined: Fri Apr 25, 2003 6:41 pm

Post by GPI »

Yes i like you too.
Post Reply