byte in PureBasic .. -127 to 127?

Just starting out? Need help? Post your questions and find answers here.
TimmyTom
User
User
Posts: 36
Joined: Mon Aug 18, 2003 8:32 am

byte in PureBasic .. -127 to 127?

Post by TimmyTom »

Isn't a byte supposed to be 0 to 255?

I am trying to write an app that searches in memory of a process (this all works just fine).. but when i search for '100' in memory (64 in hex) Purebasic tells me it's -56 ..

I am mystified here :)

Tim
sverson
Enthusiast
Enthusiast
Posts: 286
Joined: Sun Jul 04, 2004 12:15 pm
Location: Germany

Post by sverson »

Unfortunately PB offers just signed integers
:arrow: viewtopic.php?t=6896&highlight=unsigned+integer
  • Byte .b 1 Byte in memory -128 to +127
    Word .w 2 Byte in memory -32768 to +32767
    Long .l 4 Byte in memory -2147483648 to +2147483647
You can treat your variables as unsigned using & (AND) $FF /$FFFF / $FFFFFFFF:

Code: Select all

sVar.b = $FF

Debug sVar
Debug sVar&$FF

If sVar>200
  Debug "unsigned"
Else
  Debug "signed"
EndIf

If sVar&$FF>200
  Debug "unsigned"
Else
  Debug "signed"
EndIf

sVar.b = -100
Debug sVar
Debug sVar&$FF

sVar.b = 200
Debug sVar
Debug sVar&$FF
:wink: sverson
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6172
Joined: Sat May 17, 2003 11:31 am
Contact:

Post by blueznl »

( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB - upgrade incoming...)
( The path to enlightenment and the PureBasic Survival Guide right here... )
Post Reply