Exercises 3.5 Exercises
1.
Develop an algorithm to convert signed decimal integers to 2's complement binary.
Use Algorithm 2.5.1 for negative numbers.
-
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.
Review the comment about “sign bit” in the list following Table 3.4.1.
-
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?
\(\displaystyle \hex{55}\)
\(\displaystyle \hex{ab}\)
\(\displaystyle \hex{f0}\)
\(\displaystyle \hex{0f}\)
\(\displaystyle \hex{80}\)
\(\displaystyle \hex{63}\)
\(\displaystyle \hex{7b}\)
4.
The following 16-bit hexadecimal values are stored in two's complement code. What are the equivalent signed decimal numbers?
\(\displaystyle \hex{1234}\)
\(\displaystyle \hex{8765}\)
\(\displaystyle \hex{5678}\)
\(\displaystyle \hex{edcc}\)
\(\displaystyle \hex{fedc}\)
\(\displaystyle \hex{07e0}\)
\(\displaystyle \hex{8000}\)
\(\displaystyle \hex{7fff}\)
\(\displaystyle \hex{8001}\)
\(\displaystyle +4660\)
\(\displaystyle -30875\)
\(\displaystyle +22136\)
\(\displaystyle -4660\)
\(\displaystyle -292\)
\(\displaystyle +2016\)
\(\displaystyle -32768\)
\(\displaystyle +32767\)
\(\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.
\(\displaystyle +100\)
\(\displaystyle -1\)
\(\displaystyle -10\)
\(\displaystyle +88\)
\(\displaystyle -127\)
\(\displaystyle -16\)
\(\displaystyle -32\)
\(\displaystyle -128\)
\(\displaystyle \hex{64}\)
\(\displaystyle \hex{ff}\)
\(\displaystyle \hex{f6}\)
\(\displaystyle \hex{58}\)
\(\displaystyle \hex{81}\)
\(\displaystyle \hex{f0}\)
\(\displaystyle \hex{e0}\)
\(\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.
\(\displaystyle +31693\)
\(\displaystyle -252\)
\(\displaystyle +1024\)
\(\displaystyle -1024\)
\(\displaystyle -1\)
\(\displaystyle -32768\)
\(\displaystyle +32767\)
\(\displaystyle -256\)
\(\displaystyle -32767\)
\(\displaystyle -128\)
\(\displaystyle \hex{7bcd}\)
\(\displaystyle \hex{ff04}\)
\(\displaystyle \hex{0400}\)
\(\displaystyle \hex{fc00}\)
\(\displaystyle \hex{ffff}\)
\(\displaystyle \hex{8000}\)
\(\displaystyle \hex{7fff}\)
\(\displaystyle \hex{ff00}\)
\(\displaystyle \hex{8001}\)
\(\displaystyle \hex{ff80}\)