Skip to main content
\(\newcommand{\doubler}[1]{2#1} \newcommand{\binary}{\mathtt} \newcommand{\hex}{\mathtt} \newcommand{\octal}{\mathtt} \newcommand{\prog}{\mathtt} \newcommand{\lt}{<} \newcommand{\gt}{>} \newcommand{\amp}{&} \)

Section2.6Exercises

1

Convert \(123_{10}\) to binary.

Hint

123 % 2 = 1 so \(d_{0} = 1\text{.}\) Then since 123 / 2 = 61, the next computation is 61 % 2 = 1.

Answer

\(\binary{1111011} = \hex{7b}\)

2

Convert the following unsigned decimal integers to 8-bit hexadecimal representation:

  1. \(100\)

  2. \(125\)

  3. \(10\)

  4. \(88\)

  5. \(255\)

  6. \(16\)

  7. \(32\)

  8. \(128\)

Answer

  1. \(\hex{64}\)

  2. \(\hex{7d}\)

  3. \(\hex{0a}\)

  4. \(\hex{58}\)

  5. \(\hex{ff}\)

  6. \(\hex{10}\)

  7. \(\hex{20}\)

  8. \(\hex{80}\)

3

Convert the following unsigned decimal integers to 16-bit hexadecimal representation:

  1. \(1024\)

  2. \(1000\)

  3. \(32768\)

  4. \(32767\)

  5. \(256\)

  6. \(65535\)

  7. \(4660\)

  8. \(43981\)

Answer

  1. \(\hex{0400}\)

  2. \(\hex{03e8}\)

  3. \(\hex{8000}\)

  4. \(\hex{7fff}\)

  5. \(\hex{0100}\)

  6. \(\hex{ffff}\)

  7. \(\hex{1234}\)

  8. \(\hex{abcd}\)

4

Invent a code that would allow us to store letter grades with plus or minus. That is, the grades A, A-, B+, B, B-,…, D, D-, F. How many bits are required for your code?

Answer

Since there are 12 values, we need 4 bits. Any 4-bit code would work. Here is one example:

Grade Code (in hex)
A \(\binary{0000}\) \(\hex{0}\)
A- \(\binary{0001}\) \(\hex{1}\)
B+ \(\binary{0010}\) \(\hex{2}\)
B \(\binary{0011}\) \(\hex{3}\)
B- \(\binary{0100}\) \(\hex{4}\)
C+ \(\binary{0101}\) \(\hex{5}\)
C \(\binary{0110}\) \(\hex{6}\)
C- \(\binary{0111}\) \(\hex{7}\)
D+ \(\binary{1000}\) \(\hex{8}\)
D \(\binary{1001}\) \(\hex{9}\)
D- \(\binary{1010}\) \(\hex{a}\)
F \(\binary{1011}\) \(\hex{b}\)