Reputation: 57
I'm currently reading "C++ Primer" and I'm on a section about bitwise operators.
I get it but I dont get this exercise..
What is the value of ~'q' << 6 on a machine with 32-bit ints and 8 bit chars, that uses Latin-1 character set in which 'q' has the bit pattern 01110001?
The Answer given was:
The final value in decimal is -7296.
How did they get there?
Basically, I need an explanation of what the whole ~'q' << 6
means and how they got that negative number.
Upvotes: 0
Views: 577
Reputation: 1897
When 'q' = 0b01110001 then in decimal format q=113. Not q(~q) = ~113 = -114 (0b1111111110001110). When we left shift -114 by 6 we get -7296 (0b1110001110000000).
Upvotes: 2