Android Question Byte type

Cenny

Active Member
Licensed User
Longtime User
Hi,

I do have a problem with the byte type.
According to the documentation the byte ha a range from -128 to 127
But why do I not get an error from the compiler when I declare:
dim a as byte=210

Cenny
 

RandomCoder

Well-Known Member
Licensed User
Longtime User
I've had to check before posting! A signed Byte is indeed -128 to 127 as stated in the documentation, but an unsigned byte is 0 to 255 and I do not know how you set which you want to use. But if you Log(a) you will see that the value is actually being store as the signed byte value of -46.
Interestingly it will even allow you to assign values outside of the -128 and +255 range without any warnings, it just converts the first 8 bits into the corresponding value.
 
Upvote 0

MaFu

Well-Known Member
Licensed User
Longtime User
I've had to check before posting! A signed Byte is indeed -128 to 127 as stated in the documentation, but an unsigned byte is 0 to 255 and I do not know how you set which you want to use.
Java knows only signed types, unsigned doesn't exist.
 
Upvote 0
Top