Skip to content

Commit

Permalink
fixed #126
Browse files Browse the repository at this point in the history
  • Loading branch information
pezy committed Apr 19, 2018
1 parent 134ceb9 commit 4cd02dd
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions ch04/README.md
Expand Up @@ -256,13 +256,11 @@ if `grade > 90`, first conditional operator's result is `high pass`. so the fina

## Exercise 4.25

> 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?
> What is the value of `~'q' << 6` on a machine with 32-bit `int`s and 8 bit `char`s, that uses Latin-1 character set in which '`q`' has the bit pattern `01110001`?
The final value in decimal representation is `-7296`.
We see the value of `~ 'q'` is negative. Left-shifting a negative value has **undefined behaviour**.

The bitwise NOT operator (`~`) yields us the Ones' Complement of `0000 0000 0000 0000 0000 0000 0111 0001`, which is `1111 1111 1111 1111 1111 1111 1000 1110`. The value of `1111 1111 1111 1111 1111 1111 1000 1110` in decimal form is `-114`. This may come as a surprise to some as the unsigned value of said binary sequence is `4294967182`. The most significant bit (the left-most bit, commonly referred to as the sign bit) is however "turned on", or `1`, which signifies a negation operation on that particular bit. The value of that particular bit is then `-2147483648`.

We then shift the bits `6` digits to the left, which yields us `1111 1111 1111 1111 1110 0011 1000 0000`. Overflowing bits were discarded. The decimal representation of the binary sequence is `-7296`.
check <https://stackoverflow.com/questions/19585507/c-not-bitwise-operator-binary-char-conversion>

## Exercise 4.26

Expand Down

0 comments on commit 4cd02dd

Please sign in to comment.