You are on page 1of 34

KNL 1253

DIGITAL ELECTRONIC

NUMBER SYSTEMS AND CODES

rohana sapawi/digital electronics 1


OUTLINE

• Binary-to-Decimal conversion
• Decimal-to binary conversion
• Octal number system
• Hexadecimal number system
• Binary Coded Decimal (BCD) Code
• Alphanumerical code
• Parity method for error detection

rohana sapawi/digital electronics 2


OBJECTIVES

Upon completion of this topic, the students will


able to:
• Convert a number from one number system
(decimal, binary, octal, hexadecimal) to its
equivalent in one of the number systems
• Represent decimal number using the BCD code;
cite the pros and cons of using BCD
• Explain the parity method for error detection

rohana sapawi/digital electronics 3


Understanding Decimal Numbers
• Decimal numbers are made of decimal digits:
(0,1,2,3,4,5,6,7,8,9)
• Difficult to represent decimal numbers directly in a digital
system
• Easier to convert them to binary
• But how many items does a decimal number represent?
– 8653 = 8x103 + 6x102 + 5x101 + 3x100
• What about fractions?
– 97654.35 = 9x104 + 7x103 + 6x102 + 5x101 + 4x100 + 3x10-
1 + 5x10-2

– In formal notation -> (97654.35)10

rohana sapawi/digital electronics 4


Understanding Octal Numbers
• Octal numbers are made of octal digits:
(0,1,2,3,4,5,6,7)
• How many items does an octal number represent?
– (4536)8 = 4x83 + 5x82 + 3x81 + 6x80 = (1362)10
• What about fractions?
– (465.27)8 = 4x82 + 6x81 + 5x80 + 2x8-1 + 7x8-2
• Octal numbers don’t use digits 8 or 9

rohana sapawi/digital electronics 5


Understanding Binary Numbers
• Binary numbers are made of binary digits (bits):
– 0 and 1
• How many items does an binary number
represent?
– (1011)2 = 1x23 + 0x22 + 1x21 + 1x20 = (11)10
• What about fractions?
– (110.10)2 = 1x22 + 1x21 + 0x20 + 1x2-1 + 0x2-2
• Groups of eight bits are called a byte
– (11001001) 2
• Groups of four bits are called a nibble.
– (1101) 2

rohana sapawi/digital electronics 6


Why Use Binary Numbers?

° Easy to represent 0 and 1 using


electrical values.
° Possible to tolerate noise.
° Easy to transmit data
° Easy to build binary circuits

AND Gate

1
0

rohana sapawi/digital electronics 7


Conversion Between Number Bases

Octal (base 8)

Decimal (base10) Binary (base 2)

Hexadecimal
(base16)

• Learn to convert between bases.

rohana sapawi/digital electronics 8


Converting decimal to binary
• To convert a decimal integer into binary, keep dividing by 2 until the quotient
is 0. Collect the remainders in reverse order.
• To convert a fraction, keep multiplying the fractional part by 2 until it
becomes 0. Collect the integer parts in forward order.
• Example: 162.375:
Least significant digit (LSD)

162 / 2 = 81 rem 0 0.375 x 2 = 0.750


81 / 2 = 40 rem 1 0.750 x 2 = 1.500
40 / 2 = 20 rem 0 0.500 x 2 = 1.000
20 / 2 = 10 rem 0
10 / 2 =5 rem 0
5/2 =2 rem 1
2/2 =1 rem 0
1/2 =0 rem 1
• So, 162.37510 = 10100010.011
Most significant
2 digit (LSD)

rohana sapawi/digital electronics 9


More examples

Convert an Integer from Decimal binary

• (13)10
• (0.625)10

rohana sapawi/digital electronics 10


Solution
1)
13 / 2 =6 rem 1
6/2 =3 rem 0
3/ 2 =1 rem 1
1/ 2 =1 rem 1

• Answer (13)10 =11012

2)
0625 x 2 = 1.250
0.250 x 2 = 0.500
0.500 x 2 = 1.000

• Answer (0.625)10=0.1012
rohana sapawi/digital electronics 11
Converting binary to decimal
• We can use the same trick to convert binary, or base 2, numbers to
decimal. The only difference is that the weights are powers of 2.
• For example, here is 1101.01 in binary:

1 1 0 1 . 0 1 Binary digits, or bits


23 22 21 20 2-1 2-2 Weights (in base 10)

• The decimal value is:


(1 x 23) + (1 x 22) + (0 x 21) + (1 x 20) + (0 x 2-1) + (1 x 2-2) =
8 + 4 + 0 + 1 + 0 + 0.25 = 13.25
Powers of 2:
20 = 1 24 = 16 28 = 256
21 = 2 25 = 32 29 = 512
22 = 4 26 = 64 210 = 1024
23 = 8 27 = 128

rohana sapawi/digital electronics 12


More Example

1) 110112
(1 x 24) + (1 x 23) + (0 x 22) + (1 x 21) + (1 x 20)
16 + 8+ 0 + 2+ 1 = 2710

2) (110110101
x 27) +(0 x 226) +(1 x 25) +(1 x 24) + (0 x 23) + (1 x 22)
+ (0 x 21) + (1 x 20)
128 + 0 + 32 + 16 + 0+ 4 +

0 + 1
= 18110
rohana sapawi/digital electronics 13
The Growth of Binary Numbers
n 2n n 2n
0 20=1 8 28=256

1 21=2 9 29=512

2 22=4 10 210=1024

3 23=8 11 211=2048

4 24=16 12 212=4096

5 25=32 20 220=1M Mega

6 26=64 30 230=1G Giga

7 27=128 40 240=1T Tera


rohana sapawi/digital electronics 14
Converting octal to decimal
1. Multiply decimal number by the base (e.g. 8)
2. The integer is the highest-order digit

3728 = 3 X 82 + 7 X 81 +2 X 80
= 3 X 64 + 7 x 8 +2 X 1
= 25010

Answer (372)8 = (250)10

rohana sapawi/digital electronics 15


Converting decimal to octal
1. Divide decimal number by the base (8)
2. The remainder is the lowest-order digit
3. Repeat first two steps until no divisor remains.
Example for (175)10:

175/ 8 = 21 rem 7
21 / 8 = 2 rem 5
2 / 8 = 0 rem 2

Answer 175 = (257)8


rohana sapawi/digital electronics 16
Converting binary to octal
To convert a binary string: 10011101010011

Split into groups of 3:


binary octal
10 011 101 010 011 000 0
001 1
010 2
010 011 101 010 011 011 3

2 3 5 2 3 100 4
101 5
Thus 100111010100112 = 235238 110 6
111 7
rohana sapawi/digital electronics 17
Converting octal to binary
To convert a octal: 235238

2 3 5 2 3 binary octal
000 0
001 1
010 011 101 010 011 010 2
011 3
100 4
101 5
Thus 235238 = 100111010100112 110 6
111 7
rohana sapawi/digital electronics 18
Base 16 is useful too
• The hexadecimal system uses 16 digits: Decimal
Decimal Binary
Binary Hex
Hex
00 0000
0000 00
0123456789ABCDEF
11 0001
0001 11
• You can convert between base 10 and 22 0010
0010 22
base 16 using techniques like the ones we 33 0011
0011 33
just showed for converting between 44 0100
0100 44
decimal and binary. 55 0101
0101 55
• For our purposes, base 16 is most useful 66 0110
0110 66
as a “shorthand” notation for binary 77 0111
0111 77
numbers. 88 1000
1000 88
99 1001
1001 99
– Since 16 = 24, one hexadecimal digit
10
10 1010
1010 AA
is equivalent to 4 binary digits. 11 1011 BB
11 1011
– It’s often easier to work with a 12 1100 CC
12 1100
number like B4 instead of 10110100. 13 1101 DD
13 1101
• Hex is frequently used to specify things 14
14 1110
1110 EE
like 32-bit IP addresses and 24-bit colors. 15
15 1111
1111 FF

rohana sapawi/digital electronics 19


Binary and hexadecimal conversions
• Converting from hexadecimal to binary is easy: just replace each
hex digit with its equivalent 4-bit binary sequence.
261.3516 = 2 6 1 . 3 516
= 0010 0110 0001 . 0011 01012
• To convert from binary to hex, make groups of 4 bits, starting from
the binary point. Add 0s to the ends of the number if needed. Then,
just convert each bit group to its corresponding hex digit.
10110100.0010112 = 1011 0100 . 0010 11002
= B 4 . 2 C16
Hex Binary Hex Binary Hex Binary Hex Binary
0 0000 4 0100 8 1000 C 1100
1 0001 5 0101 9 1001 D 1101
2 0010 6 0110 A 1010 E 1110
3 0011 7 0111 B 1011 F 1111
rohana sapawi/digital electronics 20
Converting Between Base 16 and Base 8
1. Convert from Base 16 to Base 2
2. Regroup bits into groups of three starting from right
3. Ignore leading zeros
4. Each group of three bits forms an octal digit.

3A9F16 = 0011 1010 1001 11112


3 A 9 F

352378 = 011 101 010 011 1112


3 5 2 3 7
rohana sapawi/digital electronics 21
Binary-Coded-Decimal (BCD)Code
Digit BCD Code Digit BCD Code
0 0000 5 0101
1 0001 6 0110
2 0010 7 0111
3 0011 8 1000
4 0100 9 1001

• Binary coded decimal (BCD) represents each decimal digit with four
bits
– Ex. 0011 0010 1001 = 32910
3 2 9

• This is NOT the same as 0011001010012


rohana sapawi/digital electronics 22
• Why do this? Because people think in decimal.
Putting It All Together

 Binary, octal, and


hexadecimal similar
 Easy to build circuits to
operate on these
representations
 Possible to convert
between the three
formats

rohana sapawi/digital electronics 23


Alphanumeric codes
• In addition to numerical data, a computer must
be able to handle nonnumerical information
• A computer should recognize codes that
represent letter of alphabet, punctuation
marks other special characters as well as
numbers
• These codes are called alphanumerical codes

rohana sapawi/digital electronics 24


Cont…
• A complete alphanumerical code would include
– 26 lowercase letter
– 26 uppercase letter
– 10 numeric digits
– 7 punctuation marks
– Anywhere from 20 to 40 other characters, such as
+, /, #, %, * and so on
• Any alphanumerical code represents all the
various characters and functions that are found
on a computer keyboard
rohana sapawi/digital electronics 25
ASCII Code

• The most widely used alphanumeric code is the


American Standard Code for Information
Interchange
• ASCII is a 7-bit code, so it has 27 = 128 possible
code groups
• Frequently used with an 8th bit for error detection
(more about that in a bit).

rohana sapawi/digital electronics 26


Partial listing of ASCII Code

rohana sapawi/digital electronics 27


Example

• The following is a message encoded in


ASCII code. What is the message?

1001000 1000101 1001100 1010000

rohana sapawi/digital electronics 28


Solution
• Convert each seven-bit code to its hex
equivalent. The result are

1001000 1000101 1001100 1010000


48 45 4C 50
• Now locate these hex values in Table
ASCII and determine the character
represented by each. The results are
HELP
rohana sapawi/digital electronics 29
Parity method for error detection

• Whenever information is transmitted from one


device (the transmitter) to another device (the
receiver), there is a possibility that errors can
occur
• Major cause of any transmission error is
electrical noise, which consists of spurious
fluctuation in voltage or current

rohana sapawi/digital electronics 30


Cont…
Example of noise
causing the error in
the transmission of
digital data

• The transmitter sends a relatively noise-free serial digital


signal over a signal line to receiver
• But, the time the signal reaches the receiver, it contains a
certain degree of noise superimposed on the original signal
• Noise is large enough in amplitude that will alter the logic level
of the signal as it does at point x
• When this occurs, the receiver may incorrectly interpret that
bit as a logic 1 which is not what the transmitter has sent
• One the simplest and most widely used schemes for error
detection is parity method
rohana sapawi/digital electronics 31
Parity Codes
• Parity codes are formed by concatenating a parity bit, P
to each code word of C.
• Parity bit is an extra bit that is attracted to a code group
that is being transferred from one location to another
• The parity bit is made either 0 and 1, depending on the
number of 1s that are contained in the code group

2 different methods

Odd-parity Even-parity

rohana sapawi/digital electronics 32


Parity Codes (Cont’d)
• In an odd-parity code, the parity bit is specified so that
the total number of ones is odd.
• In an even-parity code, the parity bit is specified so that
the total number of ones is even.

P Information Bits

11000011 01000011
 
Added even parity bit Added odd parity bit

rohana sapawi/digital electronics 33


Parity Code Example
• Concatenate a parity bit to the ASCII code for
the characters 0, X, and = to produce both
odd-parity and even-parity codes.

Character ASCII Odd-Parity Even-Parity


ASCII ASCII
0 0110000 10110000 00110000

X 1011000 01011000 11011000

= 0111100 10111100 00111100

rohana sapawi/digital electronics 34

You might also like