What is a two's complement Integer?

6.3k Views Asked by At

Java Datatypes like int,short,byte are two's complement integers ,as they menioned it in here . what information does it give when someone says that in java , int ,short or byte are two's complement integers ?

Update : i wanted to know why 2's complement is prefered over other representations ?

1

There are 1 best solutions below

0
On

it tells you how signed values (+/-) are represented in binary form.

for example

24 in simple binary form is 00011000

  • one's complement is 11100111 (inverting all bits)
  • two's complement is computed by adding 1 to the one's complement value

--> 11101000 is the two's complement for -24

that's why (as an example) in java the range of a byte-value is -128 ... 127 all values having a '1' in the 2^7 position are negative.