Android Question Byte type

Discussion in 'Android Questions' started by Cenny, Jun 6, 2015.

  1. Cenny

    Cenny Member Licensed User


    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

    r.babazadeh likes this.
  2. RandomCoder

    RandomCoder Well-Known Member Licensed 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.
    r.babazadeh and Peter Simpson like this.
  3. Cenny

    Cenny Member Licensed User

    thanks for your reaction.

  4. MaFu

    MaFu Well-Known Member Licensed User

    Java knows only signed types, unsigned doesn't exist.
    Peter Simpson likes this.