Page 1 of 1

byte in PureBasic .. -127 to 127?

Posted: Mon Feb 21, 2005 12:48 am
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

Posted: Mon Feb 21, 2005 1:18 am
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

Posted: Mon Feb 21, 2005 4:36 am
by blueznl