1

The range of primitive data type BYTE (size 8 bits ) in Java is mentioned as -128 to 127. I can understand that maximum number which I can write using 7 bits ( leaving one for sign ) in binary is 1111111 which is 127 in base 10.

What I am not able to comprehend is the lower limit i.e. -128.

Can someone please throw light on how should I arrive to -128 as lower limit for byte.

Thanks to all in advance.

BlueStar
  • 59
  • 1
  • 6
  • 4
    Do you know about [Two's complement](https://en.wikipedia.org/wiki/Two%27s_complement)? – Andy Turner Aug 01 '16 at 07:19
  • 1
    You have 256 values. They're not distributed from 0 to 255 but from -128 to 127 since java has no unsigned types. – f1sh Aug 01 '16 at 07:19
  • @f1sh except `char` – Henry Aug 01 '16 at 07:21
  • `10000000` is the smallest number that can be represented using 8 bits (in two's complement). The left most bit is "1", means that the number is negative. Flipping all bits and add "1" to the result, gives 128 (the sign is negative, so -128 is the final result). – Maroun Aug 01 '16 at 07:22
  • The top, 8th bit signifies that the number is negative. From -128 to -1 there is 128 negative values (and there is 128 non-negative values) – Peter Lawrey Aug 01 '16 at 07:33

0 Answers0