0% found this document useful (0 votes)
81 views16 pages

Chapter Four Number Systems and Codes

This document discusses number systems and codes in computer architecture. It covers decimal, binary, and conversion between the two number systems. The key points are: - Number systems use distinct symbols to represent digits, with the most common being decimal (base 10) and binary (base 2). - Decimal represents numbers as strings of 0-9 digits multiplied by increasing powers of 10. Binary uses 0-1 bits multiplied by increasing powers of 2. - Conversions between decimal and binary can be done using either weighted digit sums or repeated division/multiplication by the base (10 or 2).
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
81 views16 pages

Chapter Four Number Systems and Codes

This document discusses number systems and codes in computer architecture. It covers decimal, binary, and conversion between the two number systems. The key points are: - Number systems use distinct symbols to represent digits, with the most common being decimal (base 10) and binary (base 2). - Decimal represents numbers as strings of 0-9 digits multiplied by increasing powers of 10. Binary uses 0-1 bits multiplied by increasing powers of 2. - Conversions between decimal and binary can be done using either weighted digit sums or repeated division/multiplication by the base (10 or 2).
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16

Computer Architecture

Chapter Four Number Systems and Codes

CHAPTER FOUR

Number Systems and Codes

4.1. Number Systems.


A number system of base (radix), r is a system that uses distinct symbols
of r digits.

Normally numbers are represented by a string of Digits/Symbols, (i.e. in


decimal system these digits are (0,1,2,3,4,5,6,7,8, and 9 ).

To determine the quantity that the number represents in any number


system, it is necessary to multiply each digit by an integer power of (r) and
then form the sum of all weighted digits.

4.2. Decimal Numbers System.


Decimal number system is a system which has a radix (r = 10) and ten
digits (0, 1, 2, 3, 4, 5, 6, 7, 8, and 9). The value of the number is the sum
of digits after each has been multiplied by its weight.

Example 4.1
( 83 )10 = 8 * 101 + 3 * 100
= 8 * 10 + 3 * 1
= 80 +3
The digit 8 has a weight of 10 (101), and the digit 3 has a weight of 1 (100).

Example 4.2
(724)10 = 7 * 102 + 2 * 101 + 4 * 100
= 7 * 100 + 2 * 10 + 4 * 1
= 700 + 20 + 4

The digit 7 has a weight of 100 (102), the digit 2 has the weight of 10 (101),
and the digit 4 has the weight of 1 (100).

1-32 Yacoup k. Hanna


Computer Architecture
Chapter Four Number Systems and Codes

4.3. Binary Numbers System


Binary numbers system is another way to count which have a radix (r = 2)
and two digits or bits (0 and 1).

4.3.1. Counting in Binary System


In decimal numbers system we count by starting at 0 and count up to 9.
Then start another digit position to the left and continue counting 10
through 99. Then start a third digit position to the left and continue
counting from 100 to 999, and so on.
In binary system, the same situation occurs when we count, except that
in binary system we have only two bits 0 and 1. Including another bit
position and continue counting, 10, 11. With three bits, we can continue
to count, 100, 101, 110, and 111. To continue counting, we need a fourth
bit, and so on. Table 4.1 shows a binary count from (0)10 through (31)10
using five bits (digits).
Table 4.1

Count Decimal Binary Count Decimal Binary


Number Number Number Number
Zero 0 00000 Sixteen 16 10000
0ne 1 00001 Seventeen 17 10001
Two 2 00010 Eighteen 18 10010
Three 3 00011 Nineteen 19 10011
Four 4 00100 Twenty 20 10100
Five 5 00101 Twenty-one 21 10101
Six 6 00110 Twenty-two 22 10110
Seven 7 00111 Twenty-three 23 10111
Eight 8 01000 Twenty-four 24 11000
Nine 9 01001 Twenty-five 25 11001
Ten 10 01010 Twenty-six 26 11010
Eleven 11 01011 Twenty-seven 27 11011
Twelve 12 01100 Twenty-eight 28 11100
Thirteen 13 01101 Twenty-nine 29 11101
Fourteen 14 01110 Thirty 30 11110
Fifteen 15 01111 Thirty-one 31 11111

2-32 Yacoup k. Hanna


Computer Architecture
Chapter Four Number Systems and Codes

From the table 4.1 it is clear that to cont from (0)10 to (31)10 in binary
numbers system we need at least five bits. The following formula decides
how high we can count with n bits, beginning with zero:

Highest decimal number = 2n – 1 … (4.1)

Example 4.3
With two bits and using equation 4.1 we can count from (0)10 to (3)10
22 – 1 = 4 – 1 = 3
With six bits and using equation 4.1 we can count from (0)10 to (63)10
26 – 1 = 64 – 1 = 63

4.3.2. Conversion from Binary to Decimal.


The value of the binary number in decimal system can be computed as
the sums of the bits after each have been multiplied by its weight. The
following examples will illustrate.

Example 4.4
(110)2 = 1 * 22 + 1 * 21 + 0 * 20
=1*4+1*2+0*1
=4+2+0
= (6)10
Starting from the left, bit 1 has a weight of 4 ( 22 ), bit 1 has the weight of
2 ( 21 ), and the bit 0 has the weight of 1 ( 20 ).

Example 4.5
( 10110.1 )2 = 1 * 24 + 0 * 23 + 1 * 22 + 1 * 21 + 0 * 20 + 1 * 2-1
= 1 * 16 + 0 * 8 + 1 * 4 + 1 * 2 + 0 * 1 + 1 * 1/2
= 16 + 0 + 4 + 2 + 0 + 0.5
= ( 22.5 )10

Starting from the left, bit 1 has a weight of 16 ( 24 ), bit 0 has a weight of
8 (23), bit 1 has a weight of 4 ( 22 ), bit 1 has a weight of 2 ( 21 ), bit 0 has
a weight of 1 ( 20 ). Then bit 1 after the binary point has a weight of 0.5
(2-1).

3-32 Yacoup k. Hanna


Computer Architecture
Chapter Four Number Systems and Codes

Example 4.6
(101.1011)2 = 1 * 22 + 0 * 21 + 1 * 20 + 1 * 2-1 + 0 * 2-2 + 1 * 2-3 + 1 * 2-4
= 1* 4 + 0*2 + 1 * 1 + 1 * 0. 5 + 0 * 0.25 + 1* 0.125 + 1* 0.0625
= 4 + 0 + 1 + 0.5 + 0 + 0.125 + 0.0625
= 5.6875
Homework
Convert the following binary numbers to decimal numbers.
a. (110110)2 b. (11010.101)2
Answer a. (54)10 b. (26.625)10

4.3.3. Conversion from Decimal to Binary


There are two methods for converting decimal numbers to binary
numbers:-

1. Sum of Weights Method


This method implies that the equivalent binary number to a given
decimal number is the set of binary weight values whose sum is equal
to the decimal number:-
2n-1 … 25 24 23 22 21 20 . 2-1 2-2 … 2-n

Binary point
Where n is the number of bits from the binary point.

Example 4.7
( 7 )10 = 4 + 2 + 1 = 1 * 4 + 1 * 2 + 1 * 1 = 1 * 22 + 1 * 21 + 1 * 20
= ( 111 )2
(13)10 = 8 + 4 + 0 +1
= 1 * 8 + 1 * 4 + 0*2 + 1*1 = 1*23 + 1*22 + 0*21 + 1* 20
= (1101)2

2. Repeated Division by 2 Method


To convert the decimal number N to an equivalent binary number, we
divide N by 2 then we divide each resulting quotient by 2 until there is
a 0 quotient. The remainders generated by each division form the
binary number. The first remainder produced is the least significant bit
(LSB) in the binary number, and the last remainder produced is the
most significant bit (MSB).

4-32 Yacoup k. Hanna


Computer Architecture
Chapter Four Number Systems and Codes

Example 4.8
Convert the following decimal numbers to their equivalent binary
numbers:
(a). ( 11 )10 (b). ( 34 )10 (c). ( 45 )10

Solution
(a). 11/2 (b). 34/2 (c). 45/2
5/2 1 → LSB 17/2 0 → LSB 22/2 1 → LSB
2/2 1 8/2 1 11/2 0
1/2 0 4/2 0 5/2 1
0 1 → MSB 2/2 0 2/2 1
1/2 0 1/2 0
0 1 → MSB 0 1 → MSB

(11)10 = (1011)2 (34)10 = (100010)2 (45)10 = (101101)2

4.3.4. Conversion of decimal fractions to binary fractions


There are two methods for converting decimal numbers to binary
numbers:-

1. Sum of Weights Method


The sum of weights method can be applied to fractional decimal
numbers as shown before. The following example illustrates the
method:-

Example 4.9
( 0.625 )10 = 0.5 + 0 + 0.125 = 1 * 2-1 + 0 * 2-2 + 1 * 2-3 = (0.101)2

2. Repeated Multiplication by 2 Method.


Decimal fractions can be converted to binary fractions by repeated
multiplication by 2. We begin by multiplying the decimal fraction by 2,
and then multiplying each resulting fractional part of the product by 2
until the fractional product is zero. The carried digits (carries)
generated by the multiplications form the binary fraction number. The
first carry produced is the (MSB), and the last carry is the (LSB).

5-32 Yacoup k. Hanna


Computer Architecture
Chapter Four Number Systems and Codes

Example 4.10
Convert the following decimal fraction numbers to there equivalent
binary fraction numbers:
(a). ( 0.625 )10 (b). ( 0.3125 )10

Solution
Carry Carry
(a). 0.625 * 2 = 1.25 1 → MSB (b). 0.3125 * 2 = 0.625 0 → MSB
0.25 * 2 = 0.5 0 0.625 * 2 = 1.25 1
0.5 * 2 = 1.0 1 → LSB 0.25 * 2 = 0.5 0
0.5 * 2 = 1.0 1 → LSB

(0.625)10 = (0.101)2 (0.3125)10 = (0.0101)2

Homework
Convert the decimal number (37.375)10 to binary number using: -
1. Sum-of-weights method.
2. Repeated division-by-2 method.
Answer (100101.011)2

4.3.5. Binary Arithmetic


Binary arithmetic is fundamental to digital computers and to many digital
systems. To understand digital systems we must have a sufficient
knowledge of binary addition, subtraction, multiplication, and division,
which can be explained briefly as follows:-

1. Binary addition
There are four basic rules for adding binary digits (bits):
0+0=0
0+1=1
1+0=1
1 + 1 = 0 with carry of 1

Note: For the last rule, the result of addition is a sum of (0) in a given
column and a carry of (1) over to the next higher column

6-32 Yacoup k. Hanna


Computer Architecture
Chapter Four Number Systems and Codes

Example 4.11
(a) 111→ carry 1→ carry
111 7
+11 +3
1010 10

(b) 100 4 (c) 101 5 (d) 1001 9


+111 +7 +1010 +10 + 1100 +12
1011 11 1111 15 10101 21

2. Binary subtraction
There are four basic rules for subtracting binary digits (bits):
0-0=0
1-1=0
1-0=1
0 - 1 = 1 with a borrow of 1

Note: When we have to subtract a 1 from 0, a borrow is required from


the next higher column, hence a (10)2 is created in the column
being subtracted.

Example 4.12
(a) 110 6 (b) 110 6 (c) 1010 10
-100 -4 - 011 -3 - 0101 -5
010 2 011 3 0101 5

Note: No borrow were needed in part (a), while borrows were needed in
(b) and (c).

3. Binary multiplication
There are four basic rules for multiplying binary digits (bits):
0*0=0
0*1=0
1*0=0
1*1=1

7-32 Yacoup k. Hanna


Computer Architecture
Chapter Four Number Systems and Codes

Example 4.13
(a) 11 3 (b) 111 7 (c) 1110 14
*11 *3 * 11 *3 *1001 * 9
11 9 111 21 1110 126
11 111 0000
1001 10101 0000
1110

1111110
4. Binary division
Binary division follows the same procedure as division in decimal
system.

Example 1.14
(a) 11 (b) 11
10 110 101 1111
10 101
010 0101
10 101
00 000

Homework
Perform the following arithmetic operations: -
a. 010111 + 001100 b. 1011 – 0110 c. 1010 * 1001 d. 1100 ÷ 0100
Answers a. 100011 b. 0101 c. 1011010 d. 0011

4.3.6. 1’S and 2’S Complements


1’S and 2’S complements of a binary numbers represents the negative
numbers in digital systems. The 2’S complement arithmetic is the
predominant method used in computers when operating with negative
numbers.

8-32 Yacoup k. Hanna


Computer Architecture
Chapter Four Number Systems and Codes

1’S Complement of a binary number


1’S complement of a binary number is simply found by changing all 1s by
0s and all 0s by 1s.

Example 4.15
Binary number 1’S Complement
1010 0101
11010 00101
110111 001000
1011011 0100100

1’S Complement Subtraction


1’S Complement subtraction method allows subtracting numbers simply
using addition operation only.

1. Subtracting a small number from a larger One


To subtract small numbers from a larger one, the procedure will be as
follows:-
a. Determine the 1’S complement of the smaller number.
b. Add the 1’S complement of the smaller number to the larger
number.
c. Add the final carry to the result. This is called an end around
carry.

Example 4.16
Subtract (1011)2 from (1110)2 using the 1’S Complement method.

Solution
a. Using Direct Method b. Using 1’S Complement Method
1110 1110
-1001 +0100 →1’S Complement
0101 10010
+1 → Carry
0011 → Result

9-32 Yacoup k. Hanna


Computer Architecture
Chapter Four Number Systems and Codes

2. Subtracting a Large Number From a Smaller One


The procedure for subtracting a large number from a smaller one is as
follows:-
a. Determine the 1’S complement of the larger number.
b. Add the 1’S complement of the larger number to the smaller
number.
c. In this case, there is no carry. The result presents the 1’S
complement of the real answer with opposite sign.
d. Take the 1’S complement of the result and change its sign to
get the final answer.

Example 4.17
Subtract (1110)2 from (1011)2 using the 1’S Complement method.

Solution
a. Using Direct Method b. Using 1’S Complement Method
1011 1011
-1110 +0001 →1’S Complement of 1110
Final answer→ -0011 1100 →1’S Complement of the answer
with opposite sign
- 0011 → Final answer
Homework
Perform the following subtractions using the 1’S complement method.
a. 100 – 011 b. 1000 – 1101
Answer a. 001 b. - 0101

2’S Complement of a Binary Number


Simply the 2’S complement of a binary number is found by adding 1 to the
1’S complement of that number.

Example 4.18
Convert the following binary numbers to their 2’S Complements.
a. 101 b. 10011
Solution
a. 010 → 1’S Complement of the binary number 101
+1 → adding 1
011 → 2’S Complement of the number 101
10-32 Yacoup k.
Hanna
Computer Architecture
Chapter Four Number Systems and Codes

b. 01100 → 1’S Complement of the binary number 10011


+1 → adding 1
01101 → 2’S Complement of the number 10011

2’S Complement Subtraction


As in 1’S complement subtraction, the 2’S complement subtraction
method allows subtracting numbers simply by using addition operation
only.

1. Subtracting a small number from a larger One


To subtract small numbers from a larger one, the procedure will be as
follows:-
a. Determine the 2’S Complement of the smaller number.
b. Add the 2’S Complement of the smaller number to the larger
number.
c. Discard the final carry from the result to obtain the answer
(always there is a carry in this case).
Example 4.19
Subtract (1001)2 from (1110)2 using the 2’S Complement method.
Solution
a. Using Direct Method b. Using 1’S Complement Method
1110 1110
-1001 +0111 →2’S Complement
0101 10101
Discarding the Carry ┘
0101 →Final Answer

2. Subtracting a Large Number From a Smaller One


The procedure for subtracting a large number from a smaller one using
2’S complement method is as follows:-
a. Determine the 2’S complement of the larger number.
b. Add the 2’S complement of the larger number to the smaller
number.
c. In this case, there is no carry. The result is in 2’S
complement form and is negative.
d. Take the 2’S complement of the result, and change the sign to
get the answer.
11-32 Yacoup k.
Hanna
Computer Architecture
Chapter Four Number Systems and Codes

Example 4.20
Subtract (1110)2 from (1011)2 using the 2’S Complement method.
Solution
a. Using Direct Method b. Using 1’S Complement Method
1011 1011
-1110 +0010 →2’S Complement of 1110
Final answer → -0011 1101 →2’S Complement of the answer
with negative sign
-0011 → Final answer
Homework
Perform the following subtractions using the 2’S complement method.
a. 100 – 011 b. 1000 – 1101
Answer a. 001 b. – 0101

4.3.7. Binary Representation of Signed Numbers


A signed number is a number which consist of both sign and
magnitude. The sign indicates whether a number is positive or negative,
and the magnitude represents the value of the number.
In binary system the sign is represented as 0 for a positive sign, and 1
for a negative sign. The left most bit of any signed number represents
the sign bit. For example a BYTE, which is, eight bit is a common unit
of information in computer systems. A byte as signed binary number
can be represented as follows for decimal values (45)10 and (-67)10:

(45)10 = (00101101)2 (-67)10 = (11000011)2


↓ ∟Magnitude ↓ ∟Magnitude
+ sign - sign

With an eight bit signed binary number, a range of values from


(01111111)2 = (+127)10 to (11111111)2 = (-127)10 can be represented.
More than one byte is used to represent larger number.

Example 4.21
Determine the decimal equivalent of the following signed binary
numbers:
a. (01011001)2 b. (10011100)2

12-32 Yacoup k.
Hanna
Computer Architecture
Chapter Four Number Systems and Codes

Solution
From the definition of signed binary numbers, it is clear that (01011001)2
is a positive number since the most significant bit is 0 and, the number
(10011100)2 is a negative number since the most significant bit is 1. The
solution will be as follows:-

a, (01011001)2 = +(1 * 26 + 0 * 25 + 1 * 24 + 1 * 23 + 0 * 22 + 0 * 21 + 1 * 20)


= + (64 + 0 + 16 + 8 + 0 + 0 + 1)
= (+89)10 Answer

b. (10011100)2 = - (0 * 26 + 0 * 25 + 1 * 24 + 1 * 23 + 1 * 22 + 0 * 21 + 0 * 20)
= - (0 + 0 + 16 + 8 + 4 + 0 + 0)
= (-28)10 Answer
Example 4.22
Determine the signed binary equivalent of the following decimal
numbers. Express the resultant signed binary number in eight bit (byte)
form:-
a. (+41)10 b. (- 47)10

Solution
Since the desired equivalent signed binary numbers have to be
expressed in eight bit form, therefore the first seven LSB’s will stands
for the magnitude and the remaining eighth bit (MSB ) stands for the
signed bit. The solution will be as follows:-

(a). 41/2 (b). 47/2


20/2 1 → LSB 23/2 1 → LSB
10/2 0 11/2 1
5/2 0 5/2 1
2/2 1 2/2 1
1/2 0 1/2 0
0 1 → MSB 0 1 → MSB

(+ 41)10 = (0 0101001)2 (- 47)10 = (1 0101111)2


(+) Sign ┘ └Magnitude (-) Sign ┘ └Magnitude

13-32 Yacoup k.
Hanna
Computer Architecture
Chapter Four Number Systems and Codes

4.3.8. Representation of Negative Binary Numbers in Digital Systems


Negative binary number in digital systems is represented in the following
two forms:-

1. 1’S Complement form


Negative binary numbers are represented in 1’S Complement form by
simply inverting all the magnitude bits (i.e. 0 to 1 and 1 to 0) and
leaving the sign bit without change as the following example:-

(-23)10 = (10010111)2 —→ (11101000)2


↑ ↑
True value 1’S Complement form

2. 2’S Complement form


Negative binary numbers are represented in 2’S Complement form by
simply adding 1 to 1’S Complement as previously discussed, and
leaving the sign bit without change as shown in the following example:-

(-23)10 = (10010111)2 —→ (11101001)2


↑ ↑
True value 2’S Complement form

Note. Most digital systems use 2’S Complement for representation


negative binary numbers for arithmetic operations.

Homework
1. Determine the decimal equivalent of the following signed numbers: -
a. (10010001)2 b. (00110111)2
Answer a. ( -17 )10 b. ( +55 )10
2. Express, the following signed decimal numbers in 1’s complement
form using byte representation: -
a. ( -22 )10 b. ( -11 )10
Answer a. (11101001)2 b. (11110100)2
3. Express, the signed numbers shown in question 2 above in 2’s
complement form.
Answer a. (11101010)2 b. (11110101)2

14-32 Yacoup k.
Hanna
Computer Architecture
Chapter Four Number Systems and Codes

4.3.9. Binary Arithmetic with Signed Numbers


1. Addition of Two Signed Binary Numbers
In binary addition, there are four cases to be considered when adding
two signed binary numbers:-
a. Both numbers are positive
The procedure for adding two positive numbers is as follows:-
(1) Add both numbers including the sign bit.
(2) The sign bit of the sum must be 0 (+ sign).
(3) If Overflow occurs into the sign bit, then the sign bit and the
magnitude of the sum will be incorrect (i.e. the result is
incorrect).

Note. When the number of bits in the sum exceeds the number of bits
in each of the numbers added, overflow results.

Example 4.23
Add (+15)10 to (+55)10. Use eight bits (byte) to represent each signed
binary numbers.

Solution
Since both numbers are positive, therefore the sign bits are 0’s, and
there is no need to 2’S Complement.
(+15)10 → 00001111
+(+55)10 → +00110111
(+70)10 01000110 → Answer
(+) Sign ┘ └Magnitude (70)
b. Adding small negative number to a larger positive one
(1) Take the 2’S complement of the magnitude of the negative
number, and leave the sign bit as it is. The positive number
remains in true form.
(2) Add the two numbers, including the sign bits of both. The
final carry discarded.
(3) The sign bit of the sum will be a 0 ( + ), and the magnitude
will be in true form.
(4) In this case, no overflow is possible.

15-32 Yacoup k.
Hanna
Computer Architecture
Chapter Four Number Systems and Codes

Example 4.24
Add (-6)10 to (+15)10. Use eight bits (byte) to represent the signed
numbers.

Solution
(+15)10 → 00001111
+(-6)10 → +11111010 →2’s complement of -6
(+9)10 discard carry← 1 00001001 → Answer
(+) Sign ┘ └Magnitude (9)

c. Adding large negative number to a smaller positive one


(1) Take the 2’S complement of the magnitude of the negative
number. Leaving the sign bit as it is. The positive number
remains in true form.
(2) Add the two numbers, including the sign bits.
(3) In this case no carry will occurs. The sum will have the
proper sign bit and the magnitude will be in 2’S complement
form.
(4) There is no possibility of overflow in this case.

Example 4.25
Add (-15)10 to (+6)10. Use eight bits (byte) to represent the signed numbers.

Solution
(+6) 10 → 00000110
+(-15) 10 → +11110001 → 2’s complement of (-15)
(-9) 10 11110111 → Answer
└ 2’s complement of ( - 9 )

Note. The result is in 2’s complement form because it is a negative


number.

16-32 Yacoup k.
Hanna

You might also like