(If you want to write up your answers using Markdown,
here is a partial, incomplete template you
can use to get started.)
Reminders:
- 0x23 means hexadecimal 23 (= 2 * 16 + 3 = 3510).
- hex A = decimal 10; B = 11; C = 12; D = 13; E = 14; F = 15
- hex A + 3 = decimal 10 + 3 = decimal 13 = hex D
- The range of unsigned integers that can be represented in 8 bits
is 0 ... 255.
- The range of signed two's complement integers that can be
represented in 8 bits is -128 ... 127.
Complete the following exercises:
- Calculate the following sums in hexadecimal and binary. Assume
the numbers represent 8-bit unsigned integers. Circle
or highlight any result
that has an overflow. Note whether the hex and binary sums
represent the same number.
1a |
Hex | |
Binary |
0x46 | |
0100 0110 |
+ 0x74 | |
0111 0100 |
|
|
1b |
Hex | |
Binary |
0x46 | |
+ 0xE9 | |
|
|
1c |
Hex | |
Binary |
0x87 | |
+ 0x74 | |
|
|
1d |
Hex | |
Binary |
0x87 | |
+ 0xE9 | |
|
-
For the 4 numbers that appear as operands above (0x46, 0x74, 0x87, 0xE9):
- Look at the binary representations and determine which represent
different numbers when considered as 8-bit two's complement signed
integers rather than unsigned integers? (How can you recognize them?)
- For each of the numbers whose value is different when
considered as unsigned vs. 2's complement, calculate both
decimal values.
- Which of the calculations in Question #1 above have operands or sums whose values
depend on whether they represent unsigned or 2's complement numbers?
(Question #2 provides part, although not all, of the answer to this question.)
Would you expect the results of the sums to be different if the
numbers were treated as 2's complement?
- For all of the sums above that would be different if interpreted
as 2's complement signed integers,
what is the value (expressed in decimal) of the 2's complement interpretation?
When does overflow occur? Is this the same as in problem (1) above?
Why or why not?
- Recalculate 1b (0x46+0xE9) using subtraction, treating 0x46 and 0xE9 as 2's
complement binary integers. In other words, calculate 0x46 - (-0xE9), in
binary. Then do the same calculation in hex. Both answers should match
your answer in 1b. (Tip: -0xE9 = 0x17. Verify this by comparing
it to the binary 2's complement value you calculated.)
1b as sub |
| |
Hex |
|
Binary |
hex/binary for 0x46 | |
0x46 | |
hex/binary for - (-0xE9) | |
- 0x17 | |
| |
- What is the floating point decimal value for 0xC1740000 if it
represents a 32-bit floating point number?
- What is the binary 32-bit floating point representation for
-1609.5?
- What is the 64-bit floating point representation for the same
number (-1609.5)?