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}{&} \)

Section3.5Exercises

1

Develop an algorithm to convert signed decimal integers to 2's complement binary.

Hint

Use Algorithm 2.5.1 for negative numbers.

Solution

  • If \(x \ge 0\)

    • Convert \(x\) to binary.

  • Else

    • Negate \(x\)

    • Convert the result to binary.

    • Compute the 2's complement of the result in the binary domain.

2

Develop an algorithm to convert integers in 2's complement binary to signed decimal.

Hint

Review the comment about “sign bit” in the list following Table 3.4.1.

Solution

  • If high-oder bit is \(0\)

    • Convert \(x\) to decimal.

  • Else

    • Compute the 2's complement of \(x\text{.}\)

    • Compute the decimal equivalent of the result.

    • Place a minus sign in front of the decimal equivalent.

3

The following 8-bit hexadecimal values are stored in two's complement code. What are the equivalent signed decimal numbers?

  1. \(\hex{55}\)

  2. \(\hex{ab}\)

  3. \(\hex{f0}\)

  4. \(\hex{0f}\)

  5. \(\hex{80}\)

  6. \(\hex{63}\)

  7. \(\hex{7b}\)

Hint

The number will be odd or even in both number bases. (Useful for checking your answers on an exam!)

Answer

  1. \(+85\)

  2. \(-85\)

  3. \(-16\)

  4. \(+15\)

  5. \(-128\)

  6. \(+99\)

  7. \(+123\)

4

The following 16-bit hexadecimal values are stored in two's complement code. What are the equivalent signed decimal numbers?

  1. \(\hex{1234}\)

  2. \(\hex{8765}\)

  3. \(\hex{5678}\)

  4. \(\hex{edcc}\)

  5. \(\hex{fedc}\)

  6. \(\hex{07e0}\)

  7. \(\hex{8000}\)

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

  9. \(\hex{8001}\)

Answer

  1. \(+4660\)

  2. \(-30875\)

  3. \(+22136\)

  4. \(-4660\)

  5. \(-292\)

  6. \(+2016\)

  7. \(-32768\)

  8. \(+32767\)

  9. \(-32767\)

5

Show how each of the following signed, decimal integers would be stored in 8-bit two's complement code. Give your answer in hexadecimal.

  1. \(+100\)

  2. \(-1\)

  3. \(-10\)

  4. \(+88\)

  5. \(-127\)

  6. \(-16\)

  7. \(-32\)

  8. \(-128\)

Answer

  1. \(\hex{64}\)

  2. \(\hex{ff}\)

  3. \(\hex{f6}\)

  4. \(\hex{58}\)

  5. \(\hex{81}\)

  6. \(\hex{f0}\)

  7. \(\hex{e0}\)

  8. \(\hex{80}\)

6

Show how each of the following signed, decimal integers would be stored in 16-bit two's complement format. Give your answer in hexadecimal.

  1. \(+31693\)

  2. \(-252\)

  3. \(+1024\)

  4. \(-1024\)

  5. \(-1\)

  6. \(-32768\)

  7. \(+32767\)

  8. \(-256\)

  9. \(-32767\)

  10. \(-128\)

Answer

  1. \(\hex{7bcd}\)

  2. \(\hex{ff04}\)

  3. \(\hex{0400}\)

  4. \(\hex{fc00}\)

  5. \(\hex{ffff}\)

  6. \(\hex{8000}\)

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

  8. \(\hex{ff00}\)

  9. \(\hex{8001}\)

  10. \(\hex{ff80}\)