Does anyone know how i can figure out binary shifts without
having to get the bit pattern? I thought i could use (number to shift) * 2^(places to shift) for << shifts and (number to shift) / 2^(places to shift) for >> shifts and >>> shifts. But the results i have been getting are just plain inconsistent. I have to take the Java Programmer certification exam soon and Sun always throws in shift questions.![]()
Desen't work
64 = 0100 0000
64 << 1 = -128
64 * 2^1 = 128 not -128
Works
40 = 0010 1000
40 << 1 = 80
40 * 2^1 = 80
Works
-128 = 1000 0000
-128 >> 2 = -32
-128 /2^2 = -32
Dosen't work
-128 = 1000 0000
-128 >>> 3 = 32
-128/2^2 = -32 not 32





Reply With Quote