Chapter 15

1: Convert the following decimal values to binary:
  1. 3

  2. 13

  3. 59

  4. 119

A1:
  1. 00000011

  2. 00001101

  3. 00111011

  4. 01110111

2: Convert the following binary values to decimal, octal, and hexadecimal:
  1. 00010101

  2. 01010101

  3. 01001100

  4. 10011101

A2:
  1. 21, 025, 0x15

  2. 85, 0125, 0x55

  3. 76, 0114, 0x4C

  4. 157, 0235, 0x9D

3: Evaluate the following expressions; assume each value is 8 bits:
  1. ~3

  2. 3 & 6

  3. 3 | 6

  4. 1 | 6

  5. 3 ^ 6

  6. 7 >> 1

  7. 7 << 2

A3:
  1. 252

  2. 2

  3. 7

  4. 7

  5. 5

  6. 3

  7. 28

4: Evaluate the following expressions; assume each value is 8 bits:
  1. ~0

  2. !0

  3. 2 & 4

  4. 2 && 4

  5. 2 | 4

  6. 2 || 4

  7. 5 << 3

A4:
  1. 255

  2. 1 (not false is true)

  3. 0

  4. 1 (true and true is true)

  5. 6

  6. 1 (true or true is true)

  7. 40

5: Because the ASCII code uses only the final 7 bits, sometimes it is desirable to mask off the other bits. What's the appropriate mask in binary? In decimal? In octal? In hexadecimal? ...

Get C Primer Plus, Fourth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.