FF000000=4278190080<2^(8*4)-1 (4 bytes)
but when I type in "System.out.println(0xff000000);
"
it shows "-16777216
". Why does it become negative in java
?
FF000000=4278190080<2^(8*4)-1 (4 bytes)
but when I type in "System.out.println(0xff000000);
"
it shows "-16777216
". Why does it become negative in java
?
The first thing you have to know is how signed numbers are represented in java: FF000000 is a sigened number and if you convert it to binary will be something like 1111 1111 0000 0000 0000 0000 0000 0000 now, the MSB is the sign bit, the rest is the number in 2's complement.
That means FF000000= -(00FFFFFF) in 2's complement, wich is -16777216.
More info about java primitive Data can be found here.