Java Primitive data types question.?

Hi there I need some help with a particular definition in java that is related to primitive data types. In many descriptions like the byte, int , long and short data types it is described in, for example, the byte stores whole number values in 8-bit signed locations from -128 to +127. I need to know what exactly are bit signed locations.

Thank You for the help

God Bless

Peter H2012-03-12T04:43:13Z

Favorite Answer

The words are in the wrong order. The byte is a location containing 8 bits, and you decide (in the declaration of the variable) whether you are going to interpret it as signed or unsigned. If it is signed, then 1 of these bits stores the sign, the 7 others store the value. In this way you can store a value between -128 and +127 in a byte. If the choice is unsigned, then all the bits are used for the value, and the range is 0 to +255.

?2012-03-12T11:30:06Z

Consider a possible four bit numbers 0000, 0001, 0010.....1110, 1111 (Decimal equivalents are 0-15). Here, we did not talk about sign at al. In fact numbers can be negative also. To take care of sign, 1 bit is left for sign. Usually left most bit is taken as sign. If that bit is 0 then the number can be considered as positive else nagative. Thus, the four bit sequence 0000, 0001, ...0111,1000,1010,.....1110, 1111 are in decimal systems as 7,6,...0,-0,-1,....-6, -7.

The same is applicable for any bit numbers