Professional Documents
Culture Documents
INTRODUCTION
The binary number system and digital codes are fundamental to digital electronics. This
chapter will elaborate on the binary number system and its relationship to other number
system such as decimal. Arithmetic operations with binary numbers are covered to
provide a basis for understanding how computers and many other types of digital system
work. Also digital codes such as binary coded decimal (BCD), Gray code and ASCII are
covered.
LEARNING OBJECTIVES
LEARNING OUTCOMES
The binary number system is simply another way to count. The binary system is less
complicated than the decimal system because it has two digits. The decimal system with
its ten digits is a based-ten system; the binary system with its two digits is a base-two
system. The two binary digits (bits) are 1 and 0.
• Base-2 system
• 2 digits/symbols: 0, 1
• Examples: 0, 1, 01, 111, 101010
• The position of each digit (bit) in a binary number can be assigned a weight
The decimal value of any binary number can be determined by adding the weights of all
bits that are 1 and discarding the weights of all bits that are 0. The following two
examples will illustrate this
Example 2.1 :
1011.1012
Solution :
1011.1012=(1x23) + (0x22) + (1x21) + (1x20) + (1x2-1) + (0x2-2) + (1x2-3)
= 8 + 0 + 2 + 1 + 0.5 + 0 + 0.125
= 11.62510
MSB LSB
With N bit, the maximum value that can be show is 2N-1 and the summation of
combinational bit can be obtain is 2N
Example 2.2:
How many combinational number can be obtain by 2 bit and what is the biggest number
can be show?
Solution :
There is 22 =4 combinational number which is 002, 012, 102 and 112
The biggest number can be show is 22-1=310 or 112
Table 2.1 below shows the differentiation of 3 bits binary number and its equivalent
decimal value
Binary Decimal
22=4 21=2 20=1
0 0 0 0
0 0 1 1
0 1 0 2
0 1 1 3
1 0 0 4
1 0 1 5
1 1 0 6
1 1 1 7
Table 2.1
Decimal number is simply expressed as a sum of powers of 2 and then 1s and 0s which
are written in the appropriate bit position. To illustrate:
= 1 0 1 1 0 12
Note that a 0 is placed in the 25, 23, 22 and 20 positions.
There are two ways (method 1 and 2) to convert a decimal whole number to its
equivalent binary-system representation. There is a method (method 3) to convert
decimal fraction to binary.
Given 2510
Step 1: Find the power of two that fulfills the following:
a. nearest to the given decimal number; and
b. its decimal number is less than or equal to the given decimal
number 22? No, because it is not the nearest. 8 (23) is nearer and still
less than 25.
25? No, because it’s decimal number, 32 is more than 25.
24? Yes, because it is the nearest and its decimal, 16 is less than 25.
Step 2: Subtract the power of two (from Step 1) from the given Decimal number
25-16=9
The result of the subtraction is 9.
Step 4: Write out the binary number based on all the powers of two from Step 1.
1 1 0 0 12
Method 1 can convert both whole numbers and fractional numbers to binary. Method 2
is to convert whole numbers to binary.
Given 4510
Quotien Remainde
L
S
1 B
Given 110012
S1: write the weights
24 23 22 21 20
weights
Binary number 1 1 0 0 1
S2: write the sum of the products of each digit with its weight
110012 =(1x24)+(1x23)+(0x22)+(0x21)+(1x20)
=16 + 8 + 1
=2510
Binary arithmetic is essential in all digital computers and in other types of digital systems.
Example 2.3:
101 – 11 = ?
In decimal
101 5
- 11 -3
10 2
Example 2.4:
111 + 11 = ?
In decimal
111 7
+ 11 +3
1010 10
BCD stands for Binary Coded Decimal Code. BCD is a way to represent each digit of a
decimal number with its 4-bit binary number. Table 2.1 shows the decimal numbers that
have been converted to BCD code.
Example 2.5:
87410
Solution :
Decimal 8 7 4
Therefore, the BCD code for 87410 is 1000 0111 0100BCD. Convert a BCD code to its
decimal equivalent.
Step 1: Break the BCD into 4-bit groups, starting from LSB
Step 2: Replace each 4-bit group with its equivalent decimal
6 8 3 9
Example 2.6:
BCD addition follows the same rules as binary addition. However, if the addition
produces a carry and/or creates an invalid BCD number, an adjustment is required to
correct the sum. The correction method is to add 6 to the sum in any digit position that
Decimal BCD
4 7 0100 0111
+ 2 5 + 0010 0101
7 2 0110 1100
6 12 (?)
0100 0111
6 is added to have ‘carry’
+ 0010 0101
0110 1100
+ 0110
0111 0010
7 2___
Example 2.7:
6 is added
BINARY NUMBERS AND CODES
Decimal BCD
BCD code is easier to convert to and from decimal number. The code produce ‘carry’
resulting longer delay time before obtaining the answer (refer example 2.5). It also used
more binary bit rather than ‘straight binary coding’. For example:
137=100010012
137=0001 0011 0111BCD
Created by Gray (1953), Gray code has no weights assigned to the bit positions. Only a
single bit change from one code word to the next in sequence. Converting binary number
to gray code can be done as follow:
If N-digit gray code is required, its binary number must have (N+1) bit. If the bits are not
enough, add as many 0 that is required so that (N+1) bit is enough on left MSB side.
Example 2.8:
Convert the binary number 1011 into 4 digits Gray code
Solution :
N=4, the sum of binary bit=4+1=5 bit
Add 0
Binary Code 0 1 0 1 1
Example 2.9:
Convert the binary number 11 into 3 digits Gray code
Solution :
Binary Code 0 0 1 1
Example 2.10:
Convert the Gray Code 1110 into binary number
Solution :
1 1 1 0
Start the
BPLK additional 25
+ DFE1013 (VERSION 3.0)
with 0
BINARY NUMBERS AND CODES
0 1 0 1
1 0 1 12 Binary Number
ASCII stands for American Standard Code for International Interchange. The code is
used in computers and electronic equipment.
processor 101100
1
ASCII code has 128 characters and symbols and represented by 7-bit binary code. It can
be considered an 8-bit code with MSB 0. The first 32 ASCII characters are non-graphic
commands only for control purposes—The ASCII Control Characters, e.g.: null, line feed,
start of text, escape
The hexadecimal system uses base 16. Thus, it has 16 possible digit symbols. It uses
the digits 0 throgh 9 plus A, B, C, D, E and F as the 16 digit symbols. Table 2.2 shows
the relationships between hexadecimal,, decimal and binary. Note that each
hexadecimal digit represents a group of four binary digits. It is important to remember
that the hex (abbreviation for hexadecimal) degits A through F are equivalent to the
decimal values of 10 though 15.
A hex number can be converted to its decimal equivalent by using the fact that each hex
digit position has a weight that is a power of 16. The LSD has a weight of 16 o = 1, the
next higher has a weight of 162 = 256 and so on. The conversion process is
demonstrated in the example below
Table 2.2
Example 2.11
Convert 42310 to hex
Quotient reminder
7
10
Therefore
It is a relatively simple matter to convert a hex number to binary. Each hex digit is
converted to it’s 4 digit equivalent as in Table 2.2 as example below
9 F 2
The binary number is grouped into groups of four bits and each group is converted
to its equivalent hex digit. Zeros are added as need to complete 4 digit group
1110100110 0011 1010 0110
3 A 6
= 3A616
1. A binary number is a weighted number in which the weight of each whole number
digit is a positive power of two and the weight of each fractional digit is a negative
power of two.
2. A binary number can be converted to a decimal number by summing the decimal
values of the weights of all the 1s in the binary numbers.
3. The basic rules for binary addition is as follows:
0+0=0
0+1=1
1+0=1
1 + 1 = 10
0–0=0
1–1=0
1–0=1
10 – 1 = 1
5. A decimal number is converted to BCD by replacing each decimal digit with the
appropriate 4-bit binary code.
6. The ASCII is a seven-bit alphanumeric code that is widely used in computer
systems for input and output of information.