Android Question Convert -64 (signed) to 192(unsigned)

mscientist33

Active Member
Licensed User
I am getting a byte which should be 192, b4a takes it as a signed byte of -64. How can I use it as unsigned as get my 192?
 

emexes

Expert
Licensed User
Unsigned Bytes would be great, although I suspect they'd be implemented as Java Ints or Shorts.

B4X:
Dim b As Byte = Rnd(-127, 0)

Dim OneWay As Int = Bit.And(b, 0xFF)

Dim AnotherWay As Int = b Mod 256

Log(b)
Log(OneWay)
Log(AnotherWay)
 
Last edited:
Upvote 0

emexes

Expert
Licensed User
If you're calculating a packet checkvalue by summing packet bytes, you can leave the signed-to-unsigned adjustment until the end.

And if the packet checkvalue and your summing variable are both Bytes, then you probably don't even need to do an adjustment at all, because they'll both be subject to the same -128..127 range wraparound.
 
Upvote 0
Top