Ch-02 Number System
Ch-02 Number System
Institute IoT
of Technology
Digital Logic Design
(CoEng3092)
By Kindu Tigabu
Objectives
Upon completion of this chapter, you will be able to:
Convert a number from one number system (decimal, binary, hexadecimal) to
its equivalent in one of the other number systems.
Cite the advantages of the hexadecimal number system.
Count in hexadecimal.
Represent decimal numbers using the BCD code; cite the pros and cons of
using BCD.
Explain the difference between BCD and straight binary.
Explain the purpose of alphanumeric codes such as the ASCII code.
Explain the parity method for error detection.
Determine the parity bit to be attached to a digital data strin 2
Introduction to Digital Logics
The most common number system in Computer
3
Decimal System
The decimal system is composed of 10 numerals or symbols(0 through 9).
The decimal system, also called the base-10 system because it has 10 digits.
Decimal numbers is a type of weighted system numbers.
The position of each digit in a decimal number indicates the magnitude of the quantity
represented and can be assigned a weight.
The value of a digit depends on its position.
The weight
The weights for whole numbers are positive powers of ten that increase from right to left.
For fractional numbers, the weights are negative powers of ten that decrease from left to
right beginning with 10-1
4
Decimal System...
Each number will be multiplied by its weight to get the actual number
Example:
Let’s consider 23 (in decimal number)
1. Express the decimal number 568.23 as a sum of the values of each digit.
2. Determine the value of each digit in 67.924.
5
Binary Numbers...
The decimal number system does not lend itself to convenient implementation in
digital systems.
It is very difficult to design electronic equipment so that it can work with 10 different
voltage levels.
Almost every digital system uses the binary (base-2) number system as the basic
number system of its operations.
It is very easy to design simple, accurate electronic circuits that operate with only
two voltage levels.
In the binary system there are only two symbols or possible digit values, 0 and 1.
It is less complicated compared to decimal numbers
In general, with n bits we can count up to a number equal to 2n-1
We can count through 2n different decimal numbers ranging from 0 to 2n - 1
6
Binary Numbers...
The binary number system is a positional system where each binary digit (bit)
carries a certain weight based on its position relative to the LSB.
It is represented using the positional number representation as
7
Binary Numbers...
1. What is the total range of decimal values that can be represented in eight bits?
2. How many bits are needed to represent decimal values ranging from 0to 12,500?
Solution
1. Here we have N = 8. Thus, we can represent decimal numbers from 0 to 28 - 1 = 255.
We can verify this by checking to see that 111111112 converts to 25510.
8
Binary Counting
Binary numbers is usually restricted to a specific number of bits.
It is based on the circuitry used to represent these binary numbers
10
The weighting structure of binary
numbers
Fractional numbers can also be represented in binary by placing bits to the right
of the binary point.
The left-most bit is the MSB in a binary fractional number and has a weight of 2 -1
= 0.5.
The fractional weights decrease from left to right by a negative power of two for
each bit.
The weight structure of a binary number is
11
The weighting structure of binary
numbers
Binary Weights
12
Decimal-to-Binary Conversion
1. Sum-of-Weights Method.
One way to find the binary number that is equivalent to a given decimal
number is to determine the set of binary weights whose sum is equal to the
decimal number
Example, 9 can be expressed as the sum of binary weights as follows:
13
Decimal-to-Binary Conversion
2. Repeated Division-by-2 Method
A systematic method of converting whole numbers from decimal to binary.
This method requires repeatedly dividing the decimal number by 2 and writing down the
remainder after each division until a quotient of 0 is obtained.
The first remainder as the LSB and the last remainder as the MSB
Process of convert decimal to any base
1. Divide the initial decimal number by the radix (base).
2. Place the remainder into the LSB (Least Significant Bit) digit of the converted
result.
3. Divide the current quotient by the radix.
4. Place the remainder into the next LSB digit of the converted result.
5. Repeat Step 3 and 4 until the quotient is 0.
14
Decimal-to-Binary Conversion
15
Decimal Fractions-to-Binary
An easyConversion
way to remember fractional binary weights is that the most significant
weight is 0.5, which is 2-1, and that by halving any weight, you get the next lower
weight;
A list of four fractional binary weights would be 0.5, 0.25, 0.125, 0.0625.
Sum-of-Weights
There is a 1 in the 2-1 position, a 0 in the 2-2 position, and a 1 in the 2-3
position
16
Decimal Fractions-to-Binary
RepeatedConversion
Multiplication by 2((Successive Products)
The process of converting decimal fractions
1. Multiply the initial decimal fraction by the radix.
2. Place the integer into the MSB (Most Significant Bit) digit of the converted
result.
3. Multiply the current fraction by the radix.
4. Place the integer into the next MSB digit of the converted result.
5. Repeat Step 3 and 4 until the fraction is 0 or the required number of bits
have been converted
17
Decimal Fractions-to-Binary
RepeatedConversion
Multiplication by 2((Successive Products)...
18
Binary to Decimal Conversion
Any binary number can be converted to its decimal equivalent simply by adding
the weights of all bits that are 1 and discarding the weights of all bits that are 0.
19
Binary to Decimal Conversion
Positional Notation Method
Example 1:Convert the binary whole number 1101101 to decimal
First determine the weight of each bit that is a .
Next find the sum of the weights to get the decimal number.
21
Binary to Decimal Conversion
Doubling Method
Another method of binary-to-decimal conversion that avoids the addition of
large numbers and keeping track of column weights.
The procedure is as follows
1. Write down the left-most 1 in the binary number.
2. Double it and add the next bit to the right.
3. Write down the result under the next bit.
4. Continue with steps 2 and 3 until finished with the binary number.
22
Binary to Decimal Conversion
Doubling Method
23
Power of Two
Special Powers of 2
210 = 1024 ≈103 is Kilo, denoted by “K”
220 = 1,048,576 ≈106 is Mega, denoted by “M”
230 = 1,073,741,824 ≈109 is Giga, denoted by “G”
240 = 1,099, 511, 627, 776 ≈1012 is Tera, denoted by “T” 24
Hexadecimal Number
The hexadecimal number system use base 16 and has sixteen characters:
It uses digits 0 through 9 plus the letters A(10), B(11), C(12), D(13), E(14) and F(15).
It is composed of 10 numeric digits and 6 alphabetic characters.
It is used primarily as a compact way of displaying or writing binary numbers.
long binary numbers are difficult to read and write because it is easy to drop or transpose a
bit.
Imagine writing a sixteen bit instruction for a microprocessor system in 1s and 0s.
It is much more efficient to use hexadecimal
It is also very easy to convert between binary and hexadecimal.
Most digital systems process binary data in groups that are multiples of four bits,
making the hexadecimal number very convenient because each hexadecimal digit
represents a 4-bit binary number.
25
Hexadecimal Number
26
Decimal to Hexadecimal Conversion
Repeated Division-by-16 Method
Divide the decimal number by 16, write quotient & remainder again, quotient
divided by 16 this process is continued till remainder is zero. Then write
remainder in reverse order to get hexadecimal number.
Process of convert decimal to any base
1. Divide the initial decimal number by the radix (base).
2. Place the remainder into the LSB (Least Significant Bit) digit of the converted
result.
3. Divide the current quotient by the radix.
4. Place the remainder into the next LSB digit of the converted result.
5. Repeat Step 3 and 4 until the quotient is 0.
27
Decimal to Hexadecimal Conversion
Convert the decimal number 650 to hexadecimal by repeated division by 16.
28
Binary to Hexadecimal Conversion
Converting a binary number to hexadecimal is a straightforward procedure.
Break the binary number into 4-bit groups, starting at the right-most bit and replace each 4-
bit group with the equivalent hexadecimal symbol.
EX1: Convert the following binary numbers to hexadecimal:
a) 1100101001010111 b) 111111000101101001
Solution
a) 1100 1010 0101 0111 b) 0011 1111 0001 0110 1001
Two zeros have been added in part (b) to complete a 4-bit group at the left.
29
Hexadecimal Binary Conversion
To convert from a hexadecimal number to a binary number, reverse the process
and replace each hexadecimal symbol with the appropriate four bits.
Each hex digit is replaced by 4-bit binary number.
Ex1: Convert 1A716 to Binary number
Solution
Convert the hexadecimal number to binary first, then to decimal.
31
Hexadecimal to Decimal
Positional value method
To convert a hex number to a decimal number, multiply each hex value by the
weight of the digit and sum the results.
Ex1 : Convert A516 to equivalent decimal.
A516 = A * x161 + 5 * 160
= 10 * 16 + 5 * 1 = 16510
Ex2 : Convert 0.B216 to equivalent decimal.
0.B216 = B * 16-1 + 2 * 16-2
= 11 /16 + 2/ 256
= 0.0625 * 11 + 2 * 0.00390625 = 0.6875 + 0.0078125
0.B216 = 0.695312510
32
Binary Arithmetic
The arithmetic of binary numbers means the operation of addition, subtraction,
multiplication and division.
Binary arithmetic operation starts from the least significant bit i.e. from the right
most side.
Binary Addition
Binary Subtraction
Binary Multiplication
Binary Division
33
Binary Addition
There are four steps in binary addition.
0+0=0
0+1=1
1+0=1
1 + 1 = 0 (carry 1 to the next significant bit)
EX1: Evaluate 11 + 1:
• In the right column, 1 + 1 = 0 with a carry of 1 to the next column to the left.
• In the middle column, 1 + 1 + 0 = 0 with a carry of 1 to the next column to the left.
• In the left column, 1 + 0 + 0 = 1.
34
Binary system complements
Complements
Complements are used in the digital computers in order to simplify the
subtraction operation and for the logical manipulations.
For each radix-r system there are two types of complements.
1. Radix Complement: The radix complement is referred to as the r's
complement
2. Diminished Radix Complement: The diminished radix complement is
referred to as the (r-1)'s complement
35
Binary system complements
As the binary system has base r = 2. So the two types of complements for the
binary system are
2's complement
1's complement
1's complement
The 1's complement of a number is found by changing all 1's to 0's and all 0's
to 1's.
36
Binary system complements
2's complement
The 2's complement of binary number is obtained by adding 1 to the Least
Significant Bit (LSB) of 1's complement of the number.
• 2's complement = 1's complement + 1
Example of 2's Complement is as follows
37
Binary Subtraction
Here are too four simple steps to keep in memory
0–0=0
0 – 1 = 1, borrow 1 from the next more significant bit
1–0=1
1–1=0
Evaluate: 110110 – 10110
Solution:
1. Make sure that the two operands have the same number of bits. If not append
‘0’ to the MSB of the operand which has less number of bits.
2. Next, find 2’s complement of the second operand(subtrahend)
3. Finally, add the complemented with the Minuend
38
Binary Subtraction
Evaluate: 110110 – 10110
Solution: ...
2’s complement of 010110 is (101101 + 1) i.e.101010.
110110 Minuend
+101010 2’s complement of subtrahend
Carry over 1 1 0 0 0 0 0 Result of addition
After dropping the carry over we get the result of subtraction to be 100000.
39
Unsigned and Signed Binary Numbers
An unsigned binary number has no arithmetic sign.
Unsigned binary numbers are therefore always positive.
An 8-bit unsigned binary integer represents all numbers from 00 16 through FF16 (010
through 25510).
Signed binary numbers, on the other hand, include both positive and negative
numbers.
The techniques used to represent the signed integers are:
Sign-magnitude approach
Ones complement approach
Twos complement approach
40
Unsigned and Signed Binary Numbers
An unsigned binary number has no arithmetic sign.
Unsigned binary numbers are therefore always positive.
41
Unsigned and Signed Binary Numbers
Represent the following decimal numbers in twos complement form. Use 7 bits to represent
the numbers.
A. +39
B. -43
Solution
A. Because the number +39 is positive, its twos complement representation is the same as
its sign-magnitude representation as shown here:
B. In this case, the given number −43 is negative. The twos complement form of
the number can be obtained as follows:
42
Digital Codes
When numbers, letters, or words are represented by a special group of symbols,
we say that they are being encoded, and the group of symbols is called a code.
When a decimal number is represented by its equivalent binary number, we
call it straight binary coding.
Digital systems all use some form of binary numbers for their internal operation,
but the external world is decimal in nature.
Conversion between the decimal and binary systems is required.
This conversions can become long and complicated for large numbers.
For this reason, a means of encoding decimal numbers that combines some
features of both the decimal and the binary systems is used in certain
situations.
43
Different Types of Binary Codes
Commonly used Binary Codes
Weighted codes
8421(BCD) Codes
2421 Codes
5211 Codes
Non-weighted binary codes
Excess-3 Codes
Gray Codes
44
Binary-Coded-Decimal(BCD) Code
In BCD each digit of a decimal number is represented by its binary equivalent
Since a decimal digit can be as large as 9, four bits are required to code each digit.
Only numbers from 0000 through 1001 are used.
The numbers 1010, 1011, 1100, 1101, 1110, and 1111 are not used in BCD
EX1: Change 874 and 943 to its BCD-code representation
Each digit is changed to its binary equivalent as follows
45
Binary-Coded-Decimal(BCD) Code
Comparison of BCD and binary
BCD is not another number system like binary, decimal, and hexadecimal.
It is the decimal system with each digit encoded in its binary equivalent.
A BCD number is not the same as a straight binary number.
A straight binary number takes the complete decimal number and represents it in binary
The BCD code converts each decimal digit to binary individually.
BCD requires more bits than straight binary to represent decimal numbers of more than
one digit
The main advantage of the BCD code is the relative ease of converting to and from decimal.
Only the four-bit code groups for the decimal digits 0 through 9 need to be remembered.
This is especially important from a hardware standpoint because in a digital system, it is
the logic circuits that perform the conversions to and from decimal.
46
ASCII Code
ASCII(american Standard Code for information interchange) is the most widely
used alphanumeric code
ASCII is a universally accepted alphanumeric code used in most computers
and other electronic equipment.
The ASCII code is a seven-bit code, and so it has 27 = 128 possible code groups.
Actually, ASCII can be considered an 8-bit code with the MSB always 0.
This 8-bit code is 00 through 7F in hexadecimal
Most computer keyboards are standardized with the ASCII.
When you enter a letter, a number, or control command, the corresponding
ASCII code goes into the computer
47
The ASCII Control Characters
48
The ASCII Control Characters
49
The ASCII Control Characters
50
Thank You!!!
51