Android Question How to force byte comparison to be 8 bits? [solved]

Didier9

Well-Known Member
Licensed User
Longtime User
I have a byte array, msg() and I want to check that specific bytes are specific values, like
B4X:
If msg(0) = 0x10 and msg(1) = 0x8F then
The problem is that when the byte value is greater than 127, the byte value is converted to a negative 32 bit number.
For instance, if the byte is 0x8F, it is converted to 0xFFFFFF8F and of course the comparison fails.
There are a number of ugly ways I can think to fix this but really how can I force a byte value to return a 0-255 value?
 

Didier9

Well-Known Member
Licensed User
Longtime User
Looks like I found a clean way. Instead of comparing to 0x8F, I declare a byte variable and compare to that
B4X:
Dim VAR_0x8F as Byte = 0x8F
If msg(1) = VAR_0x8F Then
and that works.
I guess otherwise 0x8F is treated as a 32 bit variable and forces the conversion of msg(1) to 32 bits
 
Last edited:
Upvote 0
Top