ProgrammingHard
What is the value of 1u << 31 >> 31 in C?
- A. 0
- B. 1
- C. 2
- D. 2147483648
Correct answer: B. 1
1u << 31 sets the top bit, and shifting right 31 places brings it down to bit 0. The unsigned shift is well defined.
More C Programming questions
- What is printed by printf("%d", 0x7FFFFFFF + 0);?
- What value is -x when x is 7 in two's complement, expressed as ~x + 1?
- What is the value of (unsigned short)(65535 + 1) on a platform where unsigned short is 16 bits?
- Which bit trick isolates the lowest set bit of an unsigned n?
- What is the parity of the number 0b1101011 (1 for odd count of set bits)?
- What is (-8) >> 1 in C if the platform uses arithmetic right shift for signed values?