Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Operations
Part II
Addition
Subtraction
Multiplication
Division
Addition
4 cases that can occur when 2 signed
numbers are added:
Addition
Both numbers positive:
ex:
00000111
+00000100
00001011
7
+4
11
Addition
Positive number with magnitude larger
than negative number:
ex:
00001111
15
+11111010
+6
00001001
9
Discard1
carry
Addition
Negative number with magnitude larger
than positive number:
ex:
00010000
+11101000
11111000
16
+24
8
Addition
Both numbers negative:
ex:
11111011
5
+11110111
+9
Discard1
11110010
14
carry
Addition
Remark:
Addition
Overflow condition:
ex: 01111101
+00111010
10110111
Magnitude
incorrect
Sign
incorrect
125
+58
183
Addition
Numbers are added two at a time:
Subtraction
Subtraction is a special case of addition.
_______________________________
Subtrahend = , Minuend =
Subtraction
Since subtraction is simply an addition
with the sign of the subtrahend changed,
the process is stated as follows:
Subtraction
ex: Perform each of the following subtraction of the signed numbers:
(a)0000100000000011
(b)0000110011110111
(c)1110011100010011
(d)1000100011100010
(a)00001000
+11111101
100000101
8
+3
5
(b)00001100
+00001001
00010101
(c)11100111
+11101101
111010100
25
+19
44
(d)10001000120
+00011110+30
1010011090
12
+9
21
Multiplication
The multiplication operation in most
computer is accomplished using addition.
Multiplication
Direct addition
Multiplication
Partial products
The multiplicand is
multiplied by each
multiplier digit beginning
with the LSD.
239multiplicand
x123multiplier
717
478
+239.
Multiplication
Partial products
239multiplicand
x123multiplier
The result of the
7171stpartprod
multiplication of the
4782ndpartprod
multiplicand by a multiplier +2393rdpartprod
Multiplication
Partial products
239multiplicand
x123multiplier
7171stpartprod
4782ndpartprod
+2393rdpartprod
29397FinalProduct
Multiplication
The sign of the product of a multiplication
depends on the signs of the multiplicand
and the multiplier according to the
following two rules:
Multiplication
Step 1: Determine if
the signs of the
multiplicand and
multiplier are the
same or different.
This determines
what the sign of the
product will be.
01010011(multiplicand)
11000101(multiplier)
Multiplicand+
Multiplier
Product
Multiplication
Step 2: Change any
negative number to
true form. Because
most computers store
negative numbers in
2s comp, a 2s comp
operation is required to
get the negative
number into true form.
01010011(multiplicand)
11000101(multiplier)
00111011(2scomp)
Multiplication
Step 3: Starting with
the LSB (multiplier),
generate the partial
products. Shift each
successive partial
product one bit to the
left.
Step 4: add each
successive partial
product to the sum of
the previous partial
products to get the
final product.
01010011(multiplicand)
11000101(multiplier)
1010011
x0111011
1010011
+1010011.
11111001
+0000000.
011111001
+1010011.
1110010001
+1010011.
100011000001
+1010011.
1001100100001
+0000000.
1001100100001
Multiplication
Step 4: if the sign
bit was determined
in step 1 is
negative, take the
2s comp of the
product. If positive,
leave the product in
true form. Attach the
sign bit to the
product.
01010011(multiplicand)
11000101(multiplier)
1001100100001(final)
0110011011111(2scomp)
Accordingtostep1
thesignbitofthe
productmustbe1
(negative).
Hence:
10110011011111
Division
The number in a division are the dividend,
the devisor, and the quotient.
dividend = quotient
devisor
The division op in computer is
accomplished using subtraction. Since
subtraction is done with an adder, division
can also be accomplished with an adder.
Division
The quotient is the
number of times that
the divisor will go into
the dividend. This
means that the divisor
can be subtracted from
the dividend a number
of times equal to the
quotient. (lets do 21/7)
21
7
14
7
7
7
0
Thedivisorwas
subtractedfromthe
dividend3timesbeforea
remainderofzerowas
obtained.Therefore,the
quotientis3.
Division
The sign of the quotient depends on the
signs of the dividend and the divisor
according to the following two rules:
Division
Step 1: Determine
if the signs of the
dividend and
divisor are the
same or different.
This determines
what the sign bit of
the quotient will
be. Initialize the
quotient to zero.
01100100(dividend)
00011001(divisor)
Dividend
+
Divisor
+
Quotient+
Division
Step 2: Subtract the
divisor from the
dividend using 2s
complement addition
to get the first partial
remainder and add 1
to the quotient.
If this partial
remainder is positive,
go to step 3.
If the partial
remainder is zero or
negative, the division
is complete.
01100100(dividend)
00011001(divisor)
01100100
+11100111(2scomp)
101001011
Quotient=00000000+00000001
=00000001
Note:Thefinal
carriesare
discarded.
Division
Step 3: Subtract the
divisor from the
partial remainder and
add 1 to the quotient.
If this partial
remainder is positive,
repeat for the next
partial remainder.
If the result is zero or
negative, the division
is complete.
Stopwhentheresult
iszero(ornegative)
Quotient=4
01100100(dividend)
00011001(divisor)
01001011
+11100111(2scomp)
100110010
Quotient=00000001+00000001
=00000010
00110010
+11100111(2scomp)
100011001
Quotient=00000010+00000001
=00000011
00011001
+11100111(2scomp)
100000000
Quotient=00000011+00000001
=00000100
Hexadecimal Numbers
We will call it for short as hex.
It has 16 characters. Digits 0-9 and letters
A-F.
It used primarily as a compact way of
displaying or writing binary numbers since
it is very easy to convert between bin and
hex.
Hexadecimal Numbers
Decimal
Binary
Hexadecimal
0000
0001
0010
0011
0100
0101
0110
0111
1000
1001
10
1010
11
1011
12
1100
13
1101
14
1110
15
1111
Hexadecimal Numbers
If you see h mixing in numbers (in the
context of computer systems), please note
that its most likely that the numbers are
hexadecimal numbers. (Be careful. h is
not one of A-F using in hex).
For example
16h=000101102
0Dh=000011012
Hexadecimal Numbers
Bin-to-Hex Conversion
(a)1100101001010111
(b)111111000101101001
1100101001010111
00111111000101101001
CA57
=CA5716
3F169
=3F16916
Hexadecimal Numbers
Hex-to-Bin Conversion
ex: Determine the binary numbers for the following hex numbers:
(a)10A4h
(b)CF8Eh
10A4 CF8E
(c)9742h
9742
0001000010100100 11001111100011101001011101000010
Hexadecimal Numbers
Hex-to-Dec Conversion
2 methods:
Hex-to-Bin first and then Bin-to-Dec.
Multiply the decimal values of each hex digits by its
weight and then take the sum of these products.
Hexadecimal Numbers
Hex-to-Dec Conversion
Hexadecimal Numbers
Hex-to-Dec Conversion
Hexadecimal Numbers
Dec-to-Hex conversion
650/16 = 40.625
0.625x16 = 10 = A
40/16 = 2.5
0.5x16
2/16 = 0.125
0.125x16 = 2 = 2
=8 =8
MSD
Octal Numbers
Like the hex, the oct provides a convenient
way to express binary numbers and codes. (btw,
its not as commonly used as hex).
8 digits: 0-7
0,1,2,3,4,5,6,7,10,11,12,13,14,15,16,17,20,
Octal Numbers
Bin-to-Oct Conversion
(a)110101 (b)101111001
(c)100110011010 (d)11010000100
Oct-to-Bin Conversion
(a)138(b)258(c)1408(d)75268
Oct-to-Dec Conversion
(a)23748
Dec-to-Oct Conversion
(a)35910