Skip to main content

Exercises 3.5 Exercises

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. \(\displaystyle \hex{55}\)

  2. \(\displaystyle \hex{ab}\)

  3. \(\displaystyle \hex{f0}\)

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

  5. \(\displaystyle \hex{80}\)

  6. \(\displaystyle \hex{63}\)

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

Hint

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

Answer
  1. \(\displaystyle +85\)

  2. \(\displaystyle -85\)

  3. \(\displaystyle -16\)

  4. \(\displaystyle +15\)

  5. \(\displaystyle -128\)

  6. \(\displaystyle +99\)

  7. \(\displaystyle +123\)

4.

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

  1. \(\displaystyle \hex{1234}\)

  2. \(\displaystyle \hex{8765}\)

  3. \(\displaystyle \hex{5678}\)

  4. \(\displaystyle \hex{edcc}\)

  5. \(\displaystyle \hex{fedc}\)

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

  7. \(\displaystyle \hex{8000}\)

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

  9. \(\displaystyle \hex{8001}\)

Answer
  1. \(\displaystyle +4660\)

  2. \(\displaystyle -30875\)

  3. \(\displaystyle +22136\)

  4. \(\displaystyle -4660\)

  5. \(\displaystyle -292\)

  6. \(\displaystyle +2016\)

  7. \(\displaystyle -32768\)

  8. \(\displaystyle +32767\)

  9. \(\displaystyle -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. \(\displaystyle +100\)

  2. \(\displaystyle -1\)

  3. \(\displaystyle -10\)

  4. \(\displaystyle +88\)

  5. \(\displaystyle -127\)

  6. \(\displaystyle -16\)

  7. \(\displaystyle -32\)

  8. \(\displaystyle -128\)

Answer
  1. \(\displaystyle \hex{64}\)

  2. \(\displaystyle \hex{ff}\)

  3. \(\displaystyle \hex{f6}\)

  4. \(\displaystyle \hex{58}\)

  5. \(\displaystyle \hex{81}\)

  6. \(\displaystyle \hex{f0}\)

  7. \(\displaystyle \hex{e0}\)

  8. \(\displaystyle \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. \(\displaystyle +31693\)

  2. \(\displaystyle -252\)

  3. \(\displaystyle +1024\)

  4. \(\displaystyle -1024\)

  5. \(\displaystyle -1\)

  6. \(\displaystyle -32768\)

  7. \(\displaystyle +32767\)

  8. \(\displaystyle -256\)

  9. \(\displaystyle -32767\)

  10. \(\displaystyle -128\)

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

  2. \(\displaystyle \hex{ff04}\)

  3. \(\displaystyle \hex{0400}\)

  4. \(\displaystyle \hex{fc00}\)

  5. \(\displaystyle \hex{ffff}\)

  6. \(\displaystyle \hex{8000}\)

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

  8. \(\displaystyle \hex{ff00}\)

  9. \(\displaystyle \hex{8001}\)

  10. \(\displaystyle \hex{ff80}\)