You are on page 1of 26

Operations on Numbers

Binary Addition
Binary addition is very simple.
Same rule as decimal
+
0 1
0
0 1
1
1 10
1 1 1 1 0 1
+ 1 0 1 1 1
---------------------
0
1
0
1
1
1 1 1 1
1
1
0 0
carries
Multiplication of Binary numbers
Much the same as decimal multiplication,
except that the multiplication operations
are much simpler
1 0 1 1 1
X 1 0 1 0
-----------------------
0 0 0 0 0
1 0 1 1 1
0 0 0 0 0
1 0 1 1 1
-----------------------
1 1 1 0 0 1 1 0
* 0 1
0 0 0
1 0 1
Complements
Common use of complement: subtraction
operation.
Perform subtraction through the addition
operation.

Two types of complements for each base-
r system:
rs complement ( radix complement )
(r-1)s complement ( diminished radix
complement)

(r-1)s Complements
(r-1)s complement for a number N with
n digits in base-r numbering system is
defined as:
(r
n
-1 ) N
Example #1: Find the 9s complement
of 12389:
= (10
5
-1 ) - 12389
= 99999 -12389 = 87610
Example #2: Find the 9s complement
of 1234:
= (10
4
-1) 1234 = 9999 -1234
= 8765
(r-1)s Complements
Example #3: Find the 1s complement of
1011001:
= (2
7
1 ) 101 1001
= 111 1111 101 1001 = 010 0110

Notice that the 1s complement of binary
numbers is formed by changing 1s to 0s
and 0s to 1s
Example: 1s complement of 0001111 is
1110000.
(rs complement)
(rs) complement for number N in base r
with n digits is defined as r
n
N
Also, rs complement= ( r-1)s
complement +1

Example #1: Find the 10s complement
of 2389:
=9999 - 2389 = 7610 + 1 = 7611
Example #2: Find the 2s complement
of 10 1100:
= 11 1111 - 10 1100 = 01 0011 + 1
= 010100
Subtraction with complements
(Unsigned Numbers)
Use the following algorithms:
1. Add M to rs complement of N

2. If M>=N, then subtract the sum to r
n

to

form the result.

3. if M<N place a negative sign - in
front of rs complement of the result

Unsigned Example #1:
Do the operation: 3250 - 72532

M = 03250
10s complement of N = + 27468
------------
30718
Since N is > M the result is:
- (10s complement 30718) =-69282

Unsigned Example #2:
Perform the operation using 2s
complement: 1010100 - 1000011
Solution:
X = 1010100 = 101 0100 (copy)
- Y = 1000011 =+ 011 1101 (2s)
1 001 0001
- 1 000 0000
001 0001
Signed Binary Numbers
01001 can be considered unsigned
binary = 9 or signed binary = +9

But, 11001 can be considered unsigned
binary = 25 or signed binary = -9
Signed numbers uses 0 for + and 1 for
- , this system is called Signed-
magnitude convention

Signed Binary Numbers
All negative numbers have 1 in leftmost
bit
Signed magnitude is mostly used in
ordinary arithmetic.
The 1s complement is mostly used in
logical operations.
The 2s complement is mostly used in
computer arithmetic.

Decimal signed-2s signed-1s signed
complement complement magnitude
-------- ----------- ------------- -----------
+ 7 0111 0111 0111
+2 0010 0010 0010
+1 0001 0001 0001
+0 0000 0000 0000
-0 --- 1111 1000
-1 1111 1110 1001
-2 1110 1101 1010
-7 1001 1000 1111
-8 1000 ------- ------
Binary Coded Decimal (BCD)
Uses 4 bits to encode one decimal digit
Example: (4321)
10

= 0100 0011 0010 0001

Invalid digits: 1010, 1011,1100,1101,
1110,and 1111.
BCD Arithmetic Rules:
1. Add 2 BCD numbers using regular binary
addition.
2. Check each nibble (4-bit), if result is
greater than 9, then add 6 to it.
3. If there is a carry between 2 nibble or
coming from 2th nibble add 6.
BCD Addition
Example: 27 0010 0111
+ 34 0011 0100
------ -----------------
61 0101 1011 > 9
+ 0110 + 6
----------------
0110 0001 (61)
BCD Addition
Example: 1 carry
59 0101 1001
+ 39 0011 1001
----------------
1001 0010
0110 (+6)
----------------
1001 1000 (98)
BCD Addition
1 1 carry
98 1001 1000
+ 89 1000 1001
---------------
1 0010 0001
+ 0110 0110 (+6 6)
---------------
1 1000 0111 (187)
Character Representation
ASCII American Standard Code for
Information Interchange

128 characters (7 bits required)
Contains:
Control characters (non-printing)
Printing characters (letters, digits,
punctuation)

ASCII Characters
Hex Equiv. Binary Character
00 00000000 NULL
07 00000111 Bell
09 00001001 Horizontal tab
0A 00001010 Line feed
0D 00001110 Carriage return
20 00100000 Space (blank)
ASCII Characters
Hex Equiv. Binary Character
30 00110000 0
31 00110001 1
39 00111001 9
41 01000001 A
42 01000010 B
61 01100001 a
62 01100010 b
Error-Detecting Code
To detect the error in data
communication, an 8th bit is added to
ASCII character to indicate its parity.
Parity bit - extra bit included with a
message to make the total number of 1s
either even or odd
The 8-bit characters included parity bits
(with even parity) are transmitted to their
destination. If the parity of received
character is not even it means at least
one bits has been changed.

Binary Storage and Registers
Register - group if binary cells that are
responsible for storing and holding the
binary information.

Register transfer operation is transferring
binary operation from one set of registers
to another set of registers.

Digital logic circuits process the binary
information stored in the registers.
Exercises
Perform the following operation using a)
radix complement b) diminished radix
complement
1. 209
10
-120
10
=
_____
10


2. 10100111
2
10001110
2
= _________
2


3. AB19
16
1EB3
16
=________
16

You might also like