Page 1 of 1
Why these codes get different results?
Posted: Tue Jun 07, 2005 8:28 am
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)
Posted: Tue Jun 07, 2005 8:47 am
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.
Posted: Tue Jun 07, 2005 11:32 am
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)
Posted: Wed Jun 08, 2005 3:03 am
by Joakim Christiansen
Byte .b 1 byte in memory -128 to +127
Edit: Damn somebody already said this, i'm tired...
