The byte data type is an 8-bit signed two's complement integer
what does this statement mean?
The byte data type is an 8-bit signed two's complement integer
what does this statement mean?
It means that byte is:
Integer number (like: 1,2,3,4...)
in range from -128 to 127
one bit reserved for sign
and 7 bits for binary representation of number:
00000001 for 1,
00000010 for 2,
00000011 for 3,
...
And I think it is better to read wiki before ask questions
When you see an 8 bit binary number, Mathematically speaking, it represents a positive integer. e.g.: (10001001)=137 So with 8bits you can have 0..255. But in computers we also need a representation for negative numbers, one basic solution for that is using one bit for showing sign of the number and 7 bits for showing the magnitude of number which is called sign-magnitude representation. e.g.:(10001001)=-9 & (0001001)=9 This way you can show numbers -127..0,0..127. Notice that I wrote the 0 two times because when magnitude is 0 the sign is not important and thus (10000000) and (00000000) both represent 0. Another way of representing a negative number is 1's complement, in which a negative number is bitwise complement of its magnitude. e.g.: (00001001)=9 & (11110110)=-9 Again representable range is -127..127 and again we have two representations for 0 i.e.: (00000000)=(11111111) But showing negative numbers this way have some benefits for implementing arithmetic operations. And then we have 2's complement. Here for negative numbers, first we make the bitwise complement of its magnitude and then we add 1 to it. e.g.: (00001001)=9 & (11110111)=9 This way the problem of having two representations for 0 could be solved and we have a representable range of -128..127.
See http://en.m.wikipedia.org/wiki/Signed_number_representations for more details. And by the way sorry for my bad English.