Why these codes get different results?

Just starting out? Need help? Post your questions and find answers here.
goomoo
User
User
Posts: 42
Joined: Sun Dec 05, 2004 9:25 am
Location: China
Contact:

Why these codes get different results?

Post by goomoo »

Hello,everyone.

Why these two Debug statements get different results?
Thanks.

Code: Select all

a.b=255
Debug Hex(a)
Debug Hex(255)
Hello, Everyone.
Thanks for your help.
Hatonastick
Enthusiast
Enthusiast
Posts: 149
Joined: Wed Apr 27, 2005 11:50 am
Location: Adelaide, Australia
Contact:

Post by Hatonastick »

Try:
Debug Hex(a & $FF)
I haven't tested it but I'm pretty sure I know what the problem is as I keep forgetting that bytes are signed in PB.
So instead of being ranged from 0 - 255 (unsigned byte), they range from -127 to 127.
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

Yes the problem is the unsigned bytes. I think PB should do variable bounds checking with debugger. At least at compile time. And I would like unsigned bytes.

Watch this code to see it demostrated

Code: Select all

a.b=255
Debug Hex(Val(StrU(a,#Byte))) ;print the unsigned value
Debug Hex(Val(Str(a))) ;print the signed value
Debug Hex(a) ;print the signed value
Debug Hex(255)
User avatar
Joakim Christiansen
Addict
Addict
Posts: 2452
Joined: Wed Dec 22, 2004 4:12 pm
Location: Norway
Contact:

Post by Joakim Christiansen »

Byte .b 1 byte in memory -128 to +127
Edit: Damn somebody already said this, i'm tired... :lol:
I like logic, hence I dislike humans but love computers.
Post Reply