You are on page 1of 3

http://teaching.idallen.com/cst8214/07f/notes/lab04notes.

txt

============================================
Notes and answers for Lab 04 (computer math)
============================================
- Ian! D. Allen - idallen@idallen.ca - www.idallen.com
Text References: ECOA2e Section 2.3, 2.4
Class Notes: http://teaching.idallen.com/cst8214/07f/
binary_math.txt
Binary Mathematics, unsigned, two's complement, etc.
hexadecimal_conversions.txt
Converting to/from hexadecimal (base 16)
overflow.txt
Calculating the OVERFLOW flag in binary arithmetic
You can check your work using any online converter; use Google to find one.
e.g. http://www.tonymarston.net/php-mysql/converter.php
A quiz is here: http://acc6.its.brooklyn.cuny.edu/~gurwitz/core5/binquiz.html
Base 36: http://www.cut-the-knot.org/recurrence/word_primes.shtml
Many bases: http://www.cut-the-knot.org/binary.shtml
1.Write down all the negative powers of two from zero ("1") to -4 ("0.0625").
1 0.5 0.25 0.125 0.0625
2.Convert 0.34375 to 0.0101 binary, stopping at four fractional bits
(ECOA2e Example 2.7 p.45).
3.Convert 6235 octal to C9D hexadecimal (ECOA2e Example 2.9 p.46).
6235 = 110 010 011 101 = 1100 1001 1101 = C9Dh
4.What are the largest and smallest integers an 8-bit word can hold
using a sign-magnitude representation? (p.47)
+ 2**7 - 1 = +127
- 2**7 - 1 = -127

(+0 -> +127)


(-0 -> -127)

5.What are the largest and smallest integers an 8-bit word can hold
using a one's complement representation?
+ 2**7 - 1 = +127
- 2**7 - 1 = -127

(+0 -> +127)


(-0 -> -127)

6.What are the largest and smallest integers an 8-bit word can hold
using a two's complement representation?
+ 2**7 - 1 = +127
- 2**7
= -128

(+0 -> +127)


(-1 -> -128)

7.What are the largest and smallest integers a 16-bit word can hold
using a two's complement representation?
+ 2**15 - 1 = +32,767
- 2**15
= -32,768

(+0 -> +32,767)


(-1 -> -32,768)

8.Convert 23 to 8-bit 00010111 binary one's complement (ECOA2e Example


2.16 p.53).
9.Write 23 decimal in octal and hexadecimal.
23 decimal = 27 octal = 2 * 8**1 + 7 * 8**0
23 decimal = 17 hexadecimal = 1 * 16**1 + 7 * 16**0
10.Convert -9 to 8-bit 11110110 binary one's complement (ECOA2e Example
2.16 p.53).
11.Write 11110110 in octal and hexadecimal.
11110110 = 011 110 110 = 366 octal

1 of 3

8/13/2008 10:52 AM

http://teaching.idallen.com/cst8214/07f/notes/lab04notes.txt

11110110 = 1111 0110 = F6 hexadecimal


12.Convert -23 to 8-bit 11101000 binary one's complement.
23 decimal = 16+4+2+1 = 00010111
complement -> 11101000
13.How do you know that a two's-complement addition has overflowed?
positive+positive=negative
negative+negative=positive

-OR-

14.Convert 23 to 8-bit 00010111 binary two's complement (ECOA2e Example


2.19 p.54).
15.Write 00010111 in octal and hexadecimal.
00010111 = 000 010 111 = 27 octal
00010111 = 0001 0111 = 17 hexadecimal
16.Convert -9 to 8-bit 11110111 binary two's complement (ECOA2e Example
2.19 p.54).
17.Write 11110111 in octal and hexadecimal.
11110111 = 011 110 111 = 367 octal
11110111 = 1111 0111 = F7 hexadecimal
18.Convert -23 to 8-bit 11101001 binary two's complement (ECOA2e Example
2.19 p.54).
19.Write 11101001 as octal and hexadecimal.
11101001 = 011 101 001 = 351 octal
11101001 = 1110 1001 = E9 hexadecimal
20.Write 10010011 as octal and hexadecimal.
10010011 = 010 010 011 = 223 octal
10010011 = 1001 0011 = 93 hexadecimal
21.Convert 8-bit 10010011 binary unsigned to 147 decimal.
128+16+2+1 = 147 decimal
22.Convert 8-bit 10010011 binary sign-magnitude to -19 decimal (note
the negative).
[remove sign bit] 0010011 = 16+2+1 = 19 -> [add sign] -19
23.Convert 8-bit 10010011 binary one's complement to -108 decimal (note
the negative).
10010011 -> [flip bits] 01101100 = 64+32+8+4 = 108 -> [add sign] -108
24.Convert 8-bit 10010011 binary two's complement to -109 decimal (note
the negative).
10010011 -> [flip bits] 01101100 -> [add one] 01101101 = 109 -> [add sign] -109
25.Copy the left column of ECOA2e Table 2.2 p.63 and perform the given
two's complement additions. Without looking, fill in the remaining four
columns based on the results. (Note: this table has one printing error in it.)
26.Convert 16-bit two's complement 1A8Ch to 6,796 decimal.
1 * 16**3 + 10 * 16**2 + 8 * 16**1 + 12 * 16**0
= 4096 + 2560 + 128 + 12 = 6,796

2 of 3

8/13/2008 10:52 AM

http://teaching.idallen.com/cst8214/07f/notes/lab04notes.txt

27.Convert 16-bit two's complement 7FFFh to 32,767 decimal.


Hard way:
7 * 16**3 + 15 * 16**2 + 15 * 16**1 + 15 * 16**0
= 28672 + 3840 + 240 + 15 = 32,767
Easy way:
07FFFh + 1 = 08000h = 2**15 (or 8 * 16**3) = 32,768
therefore 07FFFh = 32,768 - 1 = 32,767
28.Convert 16-bit two's complement 8000h to decimal -32,768 (note the
negative).
8000h -> [flip bits] 7FFFh -> [add one] 8000h = 32,768 -> [add sign] -32,768
29.Convert 16-bit two's complement A123h to decimal -24,285 (note the
negative).
A123h -> [flip bits] 5EDCh -> [add one] 5EDDh = 24,285 -> [add sign] -24,285
30.Convert 16-bit two's complement FFFF to decimal -1 (note the negative).
FFFFh -> [flip bits] 0000h -> [add one] 0001h = 1 -> [add sign] -1
-OR- note that FFFFh + 1 = 0000h (zero), therefore FFFFh = 0 - 1 = -1
31.Circle the negative numbers (16-bit two's complement):
8000h 8001h 9FC5h A123h BFFFh
32.Add 16-bit two's complement ABCDh to 7FFFh and give the Result, Carry,
and Overflow. Is the result correct?
ABCDh + 7FFFh = 2BCCh [carry on] [no overflow possible] [correct]
33.Add 16-bit two's complement 8A9Ch to ABCDh and give the Result, Carry,
and Overflow. Is the result correct?
8A9Ch + ABCDh = 3669h [carry on] [overflow on] [wrong answer]
34.Add 16-bit two's complement 9999h to 4321h and give the Result, Carry,
and Overflow. Is the result correct?
9999h + 4321h = DCBAh [no carry] [no overflow possible] [correct]

3 of 3

8/13/2008 10:52 AM

You might also like