Question: -
The following example is part of Kathy certification book.
The following examples shows hexadecimal value equals to binary (8 = 1000)
But the definition says left most 1 is equal to negative sign.
How can I differenciate which one is value (8=1000) and which one is negative or positive sign value?
Example :-
class BitShift {
public static void main(
String [] args) {
int x = 0x80000000;
System.out.println("Before shift x equals " + x);
x = x << 1;
System.out.println("After shift x equals " + x);
}
}
To understand the preceding example, we�ll convert the hexadecimal number to a
bit number. Fortunately, it�s pretty simple to convert from hexadecimal to bits. Each
hex digit converts to a four-bit representation, as we can see here:
8 0 0 0 0 0 0 0
1000 0000 0000 0000 0000 0000 0000 0000
In the preceding example, the very leftmost bit represents the sign (positive or
negative). When the leftmost bit is 1, the number is negative; and when it is 0, the
number is positive. Running our program gives us the following:
%java BitShift
Before shift x equals -2147483648
After shift x equals 0