A question on a mock exam is as follows: Given the byte with a value of 01110111, which of the following statements will produce 00111011? A) 0x77 << 1; B) 0x77 >>> 1; C) 0x77 >> 1; D) None of the above The answer is 'B' and 'C'. I understand the concept of shifting bits but isn't the byte with a value of 01110111 the equivalent of 128 and isn't Ox77 the equivalent of 119. I'm missing the point here and would appreciate it if someone could shed some light on this. Thanks very much.
Originally posted by Michael Scott: but isn't the byte with a value of 01110111 the equivalent of 128 and isn't Ox77 the equivalent of 119
Just 1 small error - the 4th bit from the right in the binary number is not set, so it is 127 - 8 = 119, or calculating it the long way: 64 + 32 + 16 + 4 + 2 + 1 = 119 [ January 30, 2003: Message edited by: John Paverd ]
I don't realy understand how it is happening. isn't Ox77 is an octal number which is equavelent to 63 in decimal base. So isn't the question should be calculated as 63 >> 1 63 >>>1 63 << 1. If yes then the answer should be something else. Plz its very urgent.
Originally posted by Naveed Ali: I don't realy understand how it is happening. isn't Ox77 is an octal number [ ... ]
Nope, 0x77 is the hexadecimal representation of the decimal number 119. The leading '0x' prefix denotes a hexadecimal notation; without the 'x' (just a leading zero) it would have been octal notation (077) of the decimal number 63. kind regards