summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGeoff Liu <cangming.liu@gmail.com>2015-03-30 09:57:43 -0600
committerGeoff Liu <cangming.liu@gmail.com>2015-03-30 09:57:43 -0600
commitdeda210b165496e28f4ff6e2f5d6700c1d4d5f67 (patch)
treecb81de07fe84dc835cc68264fff09ada46aabd2e
parent6d01ff752bae3edf866bfeb7a810af3975ebbcb4 (diff)
parente267eed62caf49d6d2b0d91c60d30b700d08729f (diff)
Merge pull request #1022 from jcmvbkbc/patch-1
c.html: fix #1021 (bitwise negation and shifting into the sign bit)
-rw-r--r--c.html.markdown4
1 files changed, 2 insertions, 2 deletions
diff --git a/c.html.markdown b/c.html.markdown
index 1696d28f..d3f20eda 100644
--- a/c.html.markdown
+++ b/c.html.markdown
@@ -234,7 +234,7 @@ int main() {
// same with j-- and --j
// Bitwise operators!
- ~0x0F; // => 0xF0 (bitwise negation, "1's complement")
+ ~0x0F; // => 0xFFFFFFF0 (bitwise negation, "1's complement", example result for 32-bit int)
0x0F & 0xF0; // => 0x00 (bitwise AND)
0x0F | 0xF0; // => 0xFF (bitwise OR)
0x04 ^ 0x0F; // => 0x0B (bitwise XOR)
@@ -242,7 +242,7 @@ int main() {
0x02 >> 1; // => 0x01 (bitwise right shift (by 1))
// Be careful when shifting signed integers - the following are undefined:
- // - shifting into the sign bit of a signed integer (int a = 1 << 32)
+ // - shifting into the sign bit of a signed integer (int a = 1 << 31)
// - left-shifting a negative number (int a = -1 << 2)
// - shifting by an offset which is >= the width of the type of the LHS:
// int a = 1 << 32; // UB if int is 32 bits wide