CSc 1301: PRINCIPLES OF COMPUTER SCIENCE
Lab 5
Binary Arithmetic
Use this to go over in class
Rules of Binary Addition
0 + 0 = 0
0 + 1 = 1
1 + 0 = 1
1 + 1 = 0, and carry 1 to the next more significant bit
For example,
00011010 + 00001100 = 00100110
carrie
= 26(base
+ 0
= 12(base
= 38(base
= 19(base
+ 0
= 62(base
= 81(base
00010011 + 00111110 = 01010001
carrie
Note: The rules of binary addition (without carries) are the same as the truths of
the XOR gate.
Rules of Binary Subtraction
0 - 0 = 0
0 - 1 = 1, and borrow 1 from the next more significant bit
1 - 0 = 1
1 - 1 = 0
For example,
00100101 - 00010001 = 00010100
0
1 10
= 37(base
- 0
0 1
= 17(base
0 1
= 20(base
0 10
00110011 - 00010110 = 00011101
0
1 1
0 10
= 51(base
- 0
0 1
0 1
= 22(base
0 1
1 1
= 29(base
-39 + 92 = 53:
1
borrow
In-CLASS PRACTICE SETS OF QUESTION
1
borrow
1 1 0 1 1 0 0 1
+ 0 1 0 1 1 1 0 0
0 0 1 1 0 1 0 1
Carryout without overflow. Sum is correct.
1
+ 0
0
Carryout
1 0 1
1 0 1
0 1 1
without
1 0 0
1 1 0
0 1 0
overflow.
1
0
1
Sum is correct.
44 + 45 = 89:
1
0 0 1 0 1 1 0 0
+ 0 0 1 0 1 1 0 1
0 1 0 1 1 0 0 1
No overflow nor carryout.
104 + 45 = 149:
1
0 1 1 0 1 0 0 0
+ 0 0 1 0 1 1 0 1
1 0 0 1 0 1 0 1
Overflow, no carryout. Sum is not correct.
-75 + 59 = -16:
1
1 0 1 1 0 1 0 1
+ 0 0 1 1 1 0 1 1
1 1 1 1 0 0 0 0
No overflow nor carryout.
-103 + -69 = -172:
1
1 0 0 1 1 0 0 1
+ 1 0 1 1 1 0 1 1
0 1 0 1 0 1 0 0
Overflow, with incidental carryout. Sum is not correct.
10 + -3 = 7:
1
0 0 0 0 1 0 1 0
+ 1 1 1 1 1 1 0 1
0 0 0 0 0 1 1 1
Carryout without overflow. Sum is correct.
127 + 1 = 128:
1
0 1 1 1 1 1 1 1
+ 0 0 0 0 0 0 0 1
1 0 0 0 0 0 0 0
Overflow, no carryout. Sum is not correct.
-1 + 1 = 0:
1
1 1 1 1 1 1 1 1
+ 0 0 0 0 0 0 0 1
0 0 0 0 0 0 0 0
Carryout without overflow. Sum is correct.
Below questions MUST be used for Lab submission
SECTION A
1) Determine the twos complement of the binary number 01100101 . Explain how
2
you did the conversion, step by step.
10011011 I inverted every digit, 0 to 1, 1 to 0, then added 1.
2)
In an eight-bit digital system, where all numbers are represented in twos complement
form, what is the largest (most positive) quantity that may be represented with those eight
bits? What is the smallest (most negative) quantity that may be represented? Express your
answers in both binary (twos complement) and decimal form.
Largest (Most Positive) 011111112 = 12710
Smallest (Most Negative) 100000002 = -12810
3) Twos complement notation really shows its value in binary addition, where
positive and negative quantities may be handled with equal ease. Add the
following byte-long (8 bit) twos complement numbers together, and then convert
all binary quantities into decimal form to verify the accuracy of the addition:
= 53
= 118
= 61
= + 12
=+ 2
= -5
1000001 = 65
1111000 = 120
00111000 = 56
= 10
= -2
= -2
= -107
=-35
=- 3
111011011 = -37
111111011 = -5
10011111 = -97
SECTION B (CHOOSE Any 5 QUESTIONS)
Problems
1. Convert the following binary numbers to their decimal
representations:
(a)
(b)
(c)
(d)
11 = 310
1101 = 1310
111011 = 5910
0101 = 510
2. Convert the following hexadecimal numbers to its
decimal representations:
(a)
(b)
(c)
(d)
11 = 1710
A1 = 16110
CEF = 331110
BA9 = 298510
3. Convert the following decimal numbers to its
hexadecimal and binary representations:
(a)
(b)
(c)
(d)
11 =
4000
42 =
4095
B16 = 10112
= FA016 = 1111101000002
2A16 = 001010102
= FFF16 = 1111111111112
4. Do the binary arithmetic:
(a)
(b)
(c)
(d)
10110
11001
10110
11111
+
+
01101
00101
01101
01011
=
=
=
=
00100011
00011110
1001
00010100
5. Do the hexadecimal arithmetic:
(a)
82CD + 1982 = 9C4F
(b)
(c)
(d)
E2C + A31 = 185D
FB28 3254 = CBD4
E2C - A31 = 3FB
6. The integers in the following computations are indicated
in hexadecimal, but represent 32-bit two's complement binary
numbers.
Perform the operations and indicate if overflow occurs and why. (If
overflow occurs the result is invalid, but show it anyway.)
(a)
BBCA270C
+ AE223464
----------
(b)
E3BA265F
+ E045B9A9
----------
(c)
E9B20F5D
- FE605C8D
----------
(d)
5FCA5243
- AE223464
----------
(e)
80000000
+ 7FFFFFFF
----------
(f)
6D4AFBC0
- F89ABCDE
----------