Sie sind auf Seite 1von 33

Number Systems and codes

Dr. V. S. Bist, STO (Electronics),


USIC, HNB Garhwal University, Srinagar (Garhwal) 246174, India
E-Mail:vsbist_usic68@yahoo.com

1.

Introduction
Number systems are useful in digital computers and the knowledge of these systems is
necessary to perform reliable, economic and easily under stable arithmetic operations.
The term digital implies to a system of counting discrete units. A physical system whose
behaviour is described by mathematical equations is simulated in a digital computer by
means of number systems. This chapter provides only a basic introduction to Number
systems and codes.

1.1

Digital systems
Digital system has such a prominent role in everyday life that we refer to the present
technological period as the digital age. Logic circuits are the basis for modern digital
computer systems. To appreciate how computer systems operate you will need to
understand digital logic and Boolean algebra. First we start out with the concept of digital
vs. analog. In binary number, we can name according to number of bits (Bit: Binary
digit) given in table 1.
Table 1: Nomenclature according to the number of bits used.
Number of bits
Nomenclature
one
Binary
two
Crumb, Tydbit or Tayste
four
NibbleorNybble
five
Nickle
Eight bits
Byte
Ten bit
Deckle
Sixteen bits
Playte
Thirty two bits
Dynner
Word
System dependent
1.1.1 Digital vs. Analog
The term digital refers to the fact that the signal is limited to only a few possible values.
In general, digits signals are represented by only two possible voltages on a wire - 0 volts
(which we called "binary 0", or just "0") and 5 volts (which we call "binary 1", or just
"1"). We sometimes call these values "low" and "high", or "false" and "true". More
complicated signals can be constructed from 1s and 0s by stringing them end-to-end, like
a necklace. If we put three binary digits end-to-end, we have eight possible combinations:
000, 001, 010, 011, 100, 101, 110 and 111. In principle, there is no limit to how many
binary digits we can use in a signal, so signals can be as complicated as you like. The
figure 1 below shows a typical analog and digital signal, firstly represented as a series of
voltage levels that change as time goes on, and then as a series of 1s and 0s.
Digital signals are the language of modern day computers. Digital signals comprise only
two states. These are expressed as ON or OFF, 1 or 0 respectively. Examples of devices
having TWO states in the home are, (i) Light Switches: Either ON or OFF (ii) Doors:
Either OPEN or CLOSED. Digital signal require greater bandwidth capacity than
1

analogue signals, thus are more expensive to communicate. This diagram shows a digital
signal.

Figure 1.(a) A digital Signal (b) An analog signal


Analog electronics uses voltages that can be any value (within limits, of course - it's
difficult to imagine a radio with voltages of a million volts). The voltages often change
smoothly from one value to the next, like gradually turning a light dimmer switch up or
down. The public dial-up service supports analogue signals. Analogue signals are what
we encounter every day of our life. Speech is an analogue signal, and varies in amplitude
(volume), frequency (pitch), and phase. The figure below shows an analog signal that
change with time.
1.2

Number systems
Many number systems are in use in digital technology. The most common are the
decimal, binary, octal, and hexadecimal systems. The decimal system is clearly the most
familiar to us because it is a tool that we use every day. Examining some of its
characteristics will help us to help us to better understand the other systems. There are
different number systems some of them are given in the following table.
Number System
base-2 (Binary)

base-7 (Septenary)

base-12 (Duodecimal)

base-3 (Trinary)

base-8 (Octal)

base-13 (Tridecimal)

base-4(Quaternary)

base-9 (Nonary)

base-14 (Quattuordecimal)

base-5 (Quinary)

base-10 (Decimal)

base-15 (Quindecimal)

base-6 (Qenary)

base-11 (Undenary)

base-16 (Hexadecimal)

Table 2: Different Number System


But in nature, Binary, octal, decimal and hexadecimal is most commonly used number system.
2

1. Binary System:
In the binary system, there are only two symbols or possible digit values, 0 and 1. This
base-2 system can be used to represent any quantity that can be represented in decimal or
other base system.
23
=8
MSB

22
=4

21
=2

20
=1

.
Binary
point

2-1
=0.5

2-2
=0.25

2-3
=0.125
LSB

2. Decimal System:
In the decimal system, there are ten symbols or possible digit values, 0 to 9. This
base-10 system can be used to represent any quantity that can be represented in binary
or other base system.
103
=1000
MSD

102
=100

101
=10

100
=1

.
Decimal
point

10-1
=0.1

10-2
=0.01

10-3
=0.001
LSD

3. Octal System:
The octal number system has a base of eight, meaning that it has eight possible digits:
0, 1,2,3,4,5,6,7.
83
= 512
MSB

82
= 64

81
=8

80
=1

.
Octal
point

8-1
=0.125

8-2
=0.015625
LSB

4. Hexadecimal System:
The hexadecimal system uses base 16. Thus, it has 16 possible digit symbols. It uses
the digits 0 through 9 plus the letters A, B, C, D, E, and F as the 16 digit symbols.
163
=4096
MSB

162
=256

161
= 16

160
=1

.
Hexadecimal
point

16-1
=0.0625

16-2
=0.00390
LSB

General rule for representing any number system (base r) by using positional notation
is as follows:
(Integer part Fractional part) r
Integer (radix point) Fractional
(an an1an2 .......a3 a2 a1a0. a1a2 a3........ am ) r
(an r n an1r n1an2 r n2 .......a3 r 3 a2 r 2 a1r 1a0 r 0 . a1r n a2 r n a3 r n ...........am r n )

Lets count from zero to ten using the decimal number system and the other number
system. Generally we use the decimal, binary, octal and hexadecimal numbers. In

addition, the following list includes ternary (or trinary, base-3), quaternary (base-4) and
dozenal (or duodecimal, base-12) numbers, which are more unusual.
Radix Base Number
BinaryBase 2:
TernaryBase 3:
Quaternary- Base 4:
QuinaryBase 5:
SenaryBase 6:
SeptenaryBase 7:
OctalBase 8:
NonaryBase 9:
DecimalBase 10:
(denary)
UndenaryBase 11:
Duodenary- Base 12:
Hexadecimal- Base 16
Sexagesimal- Base 60

Number Containing
0 to 1
0 to 2
0 to 3
0 to 4
0 to 5
0 to 6
0 to 7
0 to 8
0 to 9

10 to 11
10 to 12
10 to 13
10 to 14
10 to 15
10 to 16
10 to 17
10 to 18
10 to 19

100 to 101

110 to 111

1000 to 1001

1010 to 1011 1100 to 1101

20 to 22
20 to 23
20 to 24
20 to 25
20 to 26
20 to 27
20 to 28
20 to 29

100 to 102
30 to 33
30 to 34
30 to 35
30 to 36
30 to 37
30 to 38
30 to 39

110 to 112
100 to 103
40 to 44
40 to 45
40 to 46
40 to 47
40 to 48
40 to 49

120 to 122
110 to 113
100 to 104
50 to 55
50 to 56
50 to 57
50 to 58
50 to 59

200 to 202
120 to 123
110 to 114
100 to 105
60 to 66
60 to 67
60 to 68
60 to 69

0 to A
0 to B
0 to F
0 to F

10 to 1A
10 to 1B
10 to 1F
10 to 1F

20 to 2A
20 to 2B
20 to 2F
20 to 2F

30 to 3A
30 to 3B
30 to 3F
30 to 3F

40 to 4A
40 to 4B
40 to 4F
40 to 4F

50 to 5A
50 to 5B
50 to 5F
50 to 5F

60 to 6A
60 to 6B
60 to 6F
100 to 10F

Table 3: Different Number System with number counting


For clarity, octal numbers are prefixed by 0 and hexadecimal numbers by $. The numbers
can, of course, be used without the prefix.
Generally used Number system

Others Number system

Decimal
Base-10

Binary
Base-2

Octal
Base-8

Hex
Base-16

Ternary
Base-3

Quaternary
Base-4

Dozenal
Base-12

00

$0

01

$1

10

02

$2

11

03

$3

10

100

04

$4

11

10

101

05

$5

12

11

110

06

$6

20

12

111

07

$7

21

13

1000

010

$8

22

20

1001

011

$9

100

21

10

1010

012

$A

101

22

11

1011

013

$B

102

23

12

1100

014

$C

110

30

10

13

1101

015

$D

111

31

11

14

1110

016

$E

112

32

12

15

1111

017

$F

120

33

13

16

10000

020

$10

121

100

14
4

17

10001

021

$11

122

101

15

18

10010

022

$12

200

102

16

19

10011

023

$13

201

103

17

20

10100

024

$14

202

110

18

Table 4: Counting 20 Numbers in different Number System.


1.3

Number-base conversion
The binary number system is a natural choice for representing the behavior of circuits
that operate in one of two states (on or off, 1 or 0). For instance, we studied a diode logic
gate when we discussed diode circuits. But before we study logic gates, you need to be
intimately familiar with the binary number system the system used by computers for
counting.
Notice, though, how much shorter decimal notation is over binary notation, for the same
number of quantities? What takes five bits in binary notation only takes two digits in
decimal notation.
Notice that the binary number system and digital logic are actually two different
concepts. A binary number is a number in base-2; it is independent of the concept of
digital logic. However, the computer revolution is attributed to the very simple fact that
mathematics in digital electronics can be represented by binary numbers. This is the
number system that we will primarily study, along with the hexadecimal (base-16)
system for convenience of representing large digits.
1.3.1 Any number system to decimal:
To convert any number system to its decimal equivalent, you have to do to calculate the
sum of all the products of bits/digits with their respective place-weight constants.
Examples:
(i)
Convert binary 11001101to decimal:
The bit on the far right side is called the Least Significant Bit (LSB), because it stands in
the place of the lowest weight (the one's place). The bit on the far left side is called the
Most Significant Bit (MSB), because it stands in the place of the highest weight (the one
hundred twenty-eight's place). Remember, a bit value of "1" means that the respective
place weight gets added to the total value, and a bit value of "0" means that the respective
place weight does not get added to the total value. With the above example, we have:
(Integer part Fractional part) r
(11001101) 2 (no fractional part )
(1 2 7 1 2 6 0 2 5 0 2 4 1 2 3 1 2 2 0 21 1 2 0 )10
(1128 1 64 0 32 0 16 1 8 1 4 0 2 11)10
(128 64 8 4 1)10
205 (Two Hundred Five)

(ii)

Convert binary 101.011 to decimal:

(Integer part Fractional part) r


(101.011) 2
(1 2 2 0 21 1 2 0 0 2 1 1 2 2 1 2 3 )10
(1 4 0 2 1 1 0 0.5 1 0.25 1 0.125)10
(4 1 0.25 0.125)10
5.375 (Five point Three Hundred Seventy Five )
*(direct method for fractional part 0.011: decimal value/23=3/8=0.375)
(iii)
Convert octal 26.11 to decimal:
(Integer part Fractional part) r
(26.11) 8
(2 81 6 80 1 8 1 1 8 2 )10
(2 8 6 1 1 0.125 1 0.015625)10
(4 1 0.25 0.125)10
5.375 (Five point Three Hundred Seventy Five )
1.3.2
Useful Equivalent for Any number system to decimal:
Wheneverany number system consists of only higher bit/digit, we can find its decimal
equivalent by using the formula:
Decimal number r n 1, where r is the base and n is the member of bits/digits
Examples:
(i)
Convert binary 111 to decimal:
Decimal number (2 3 1)10 8 1 7
(ii)
Convert octal 77 to decimal:
Decimal number (8 2 1)10 63
(iii)
Convert Quinary 44 to decimal:
Decimal number (5 2 1)10 24
1.3.3 Decimal to any number system:
To convert any decimal number system to its any number equivalent, decimal number is
repeatedly divide by radix, and the remainder after each division is used to indicate the
coefficient of that number to be formed in the case of integer first remainder is the Least
Significant bit/ digit and multiplying by radix and recording any carriers in the integers
position in case of fraction first carriers in the integers is the Least Significant bit/ digit.
Examples:
(i)
Convert decimal l0.10 to binary:
a. Integer part:
2 10 Remainder
2 5
0
LSB
2 2
1
2 1
0
0
1
MSB

b. Fractional part:
0.10 x2 = 0.20;
0.20 x2 = 0.40;

Fractional part
0.20 with carry of
0.40

Integer part
0
0

MSB

0.40 x2 =
0.80 x2 =
0.60 x2 =
0.40 x2 =

0.80;
1.60;
1.40;
0.80;

0.80
0.60
0.40
0.80

0
1
1
0

Repeat
LSB

(10.10)10= (1010.00110)2
(ii)

Convert decimal l0.10 to Octal:


a. Integer part:
8 10 Remainder
8 1
2
LSB
0
1
MSB
b. Fractional part:
0.10 x8 =
0.80 x8 =
0.40 x8 =
0.20 x8 =
0.60 x8 =
0.80 x8 =

0.80;
6.40;
3.20;
1.60;
4.80;
6.40;

Fractional part
0.80 with carry of
0.40
0.20
0.60
0.80
0.40

Integer part
0
6
3
1
4
6

MSB

Repeat
LSB

(10.10)10= (12.063146)8
(iii)

Convert decimal l0.10 to Hexadecimal:


a. Integer part:
16 10 Remainder
0
A
LSB
b. Fractional part:

0.10 x16 = 1.60;


0.60 x16 = 9.60;
0.60 x16 = 9.60;

Fractional part
0.60 with carry of
0.60
0.60

Integer part
1
9
9

MSB
Repeat

(10.10)10= (A.19)16
(iv)

Convert decimal l0.10 to binary to Quinary:


a. Integer part:
5 10 Remainder
5 2
0
LSB
0
2
MSB
b. Fractional part:
0.10 x5 = 0.50;
0.50 x5 = 2.50;
0.50 x5 = 2.50;

Fractional part
0.80 with carry of
2.50
2.50

Integer part
0
2
2

MSB
Repeat
7

(10.10)10= (12.063146)8
1.3.4 Binary to whose base in the power of 2 and vice versa:
Use binary-power of 2methods, in this method the binary bits are grouped into groups of
(power of 2) on each side of the binary point with zero added on either side if needed to
complete a group of power of 2. Then each group of power of 2 bits is converted to its
power of 2equivalents (2 bits- Quaternary; 3 bits- Octal: 4 bits-Hexadecimal etc).
Since Quaternary, Octal, Hexadecimal is the second, third, and fourthpower of two
(binary base), we can convert each digit of Quaternary, Octal, and Hexadecimal into its
two, three, and four bit binary equivalent.
a. Binary to octal and vice versa:
Use binary-triple method, in this method the binary bits are grouped into groups of three
on each side of the binary point with zero added on either side if needed to complete a
group of three. Then each group of three bits is converted to its octal equivalent.
Since eight (octal base) is the third power of two (binary base), we can convert each digit
of octal into its three bit binary equivalent.
To illustrate:
(i)
Convert binary l0.10 to octal:
Binary
Grouping
Octal
10.10
010.010
2.2
(ii)

Convert octal 2.2 to binary:


ctal
Grouping
Binary
2.2
010.010
010.010

b. Binary to Hexadecimal and vice versa:


Binary number is easily accomplished by partitioning the binary number into group of
four bits starting from the binary point to left (integer part) and right (fractional part)
directly converted to Hexadecimal. It may be necessary to add zeros to the left group; if it
does not end in exactly four bits. Then each group of four bits is converted to its
hexadecimal.
Similarly hexadecimal to binary: Since sixteen (hexadecimal base) is the fourth power of
two (binary base), we can convert each hexadecimal digit of into its four bit binary
equivalent.
Examples:
(iii)
Convert Binary l0.10 to hexadecimal:
Binary
10.10

Grouping
0010.0010

Hexadecimal
2.2

(iv)

Convert hexadecimal to l0.10 to binary:


Hexadecimal Grouping
Binary
2.2
0010.0010 0010.0010

1.3.5

Hexadecimal to Octal and vice versa:


8

Hexadecima l Binary (see above para 1.4.4(b)) Octal (see above para 1.4.4(a))
Octal Binary (see above para 1.4.4(a)) Hexadecima l (see above para 1.4.4(b))
1.3.6

Hexadecimal to Binary and vice versa:

Hexadecima l Binary (see above para 1.4.5)


Binary (see above para 1.4.4) Hexadecima l (see above para 1.4.5)
1.4

Negative numbers:

There are two types of binary numbers Unsigned and Signed Numbers can be represented
in the following manner:
bn-1

b1

b0

b1

b0

Magnitude
MSB
(a) Unsigned number
bn-1

bn-2

Magnitude
Sign bit MSB
0 denotes +
1 denotes (b) Signed number
1.5.1 Unsigned binary number: The input data which does not include (+) or (-) signs
and represents only the magnitude of the corresponding decimal number is called
unsigned binary number. Smallest 8-bit unsigned number is 0000 0000 00H 00
decimal and largest 8-bit unsigned number is 11111111 FFH 255 decimal. We can
add and subtract unsigned binary numbers provided certain conditions are satisfied.
For an n-bit unsigned binary number, all n bits are used to represent the magnitude of the
number. Unsigned Binary Numbers cannot represent negative numbers. For an n-bit
binary number its decimal equivalent varies in the following relation:
0 <= D <= 2n 1
Where D = decimal equivalent value
Overflow: for 8-bit arithmetic addition of two unsigned binary numbers whose sum is
greater than 255 causes an overflow, a carry into ninth bit. Most microprocessors have a
logic circuit called a carry flag. This carry flag detects a carry into the ninth column
and warns us that the 8 bit answer is invalid.
Let's try adding 17 and 19 to see how this overflow condition works for excessive
positive numbers:

(17)10 (10001) 2
(19)10 (10011) 2
(36)10 (100100) 2
The answer(100100)2 interpreted with the sixth bit as the 25place, is actually equal to -28
(ones compliment), not +36 as we should get with +17 and +19 added together!
Obviously, this is not correct.
General rule for detecting overflow when adding two n-bit numbers using either One's
Complement or Two's Complement Addition. An overflow occurs when the addition of
two positive numbers results in a negative value or the addition of two negative numbers
results in a positive value cannot occur when adding a positive number and a negative
number.
1.5.2 Signed binary number: Since digital computer and calculators handle positive as
well as negative numbers, some means is required for representing the sign of the number
(+ or ). This is usually done by placing another bit called sign bit to the left of the
magnitude bit. Sign bit including magnitude is called sign - magnitude number. Sign
magnitude numbers have limited use because they require complicated arithmetic circuit.
For an n-bit/digit signed number, n-1 bits/digits are used to represent the magnitude of
the number; the leftmost bit (MSB/MSD) is, generally, used to indicate the sign of the
number. The sign bit can be represented as; lower number for positive number and
higher number for negative number. But the magnitude of signed binary numbers can
be represented in the following three ways.
1. Signed-Magnitude representation
2. Signed - (r-1)'s Complement representation
3. Signed - r's complement representation
In signed-magnitude, - (any number) is obtained from + (any number) by changing the
sign bit in the leftmost position from low number to higher number. In Signed (r-1)'s
Complement,- (any number) is obtained by (r-1)'s Complement of any number including
the sign bit/digit.In Signed (r)'s Complement,- (any number) is obtained by (r)'s
Complement of any number including the sign bit/digit.
Table 5 lists all possible four bit signed binary number in the three representations.

Decimal
+7
+6
+5
+4
+3
+2
+1
+0
-0
-1
-2
-3
-4

Signed-2s
Complement
0111
0110
0101
0100
0011
0010
0001
0000
1111
1110
1101
1100

Signed-1s
Complement
0111
0110
0101
0100
0011
0010
0001
0000
1111
1110
1101
1100
1011

Signed
Magnitude
0111
0110
0101
0100
0011
0010
0001
0000
1000
10001
10010
10011
10100
10

-5
-6
-7
-8

1011
1010
10101
1010
1001
10110
1001
1000
10111
1000
Table 5: Signed Binary Number
Table 6 lists all possible four bit signed octal number in the three representations.

Decimal
+7
+6
+5
+4
+3
+2
+1
+0
-0
-1
-2
-3
-4
-5
-6
-7
-8

Signed-8s
Signed-7s
Complement
Complement
07
07
06
06
05
05
04
04
03
03
02
02
01
01
00
00
77
77
76
76
75
75
74
74
73
73
72
72
71
71
70
70
Table 6: Signed octal Number

Signed
Magnitude
07
06
05
04
03
02
01
00
70
71
72
73
74
75
76
77
-

Table 7 lists all possible four bit signed decimal number in the three
representations

Decimal
+7
+6
+5
+4
+3
+2
+1
+0
-0
-1
-2
-3
-4
-5

Signed-10s
Complement
07
06
05
04
03
02
01
00
99
98
97
96
95

Signed-9s
Complement
07
06
05
04
03
02
01
00
99
98
97
96
95
94

Signed
Magnitude
07
06
05
04
03
02
01
00
90
91
92
93
94
95
11

-6
-7
-8

94
93
96
93
92
97
92
Table 7: Signed Decimal Number
1.5.2a Sign-and-Magnitude Representation.
For an n-bit signed binary number, the MSB (leftmost bit) is the sign bit and the
remaining n-1 bits represent the magnitude.
- (2n-1 - 1) <= D <= + (2n-1 1)
Includes a representation for -0 and +0.
Example: -7+6 = -1
(i)
Using binary -7 = 1111, + 6 = 0110
Sign Magnitude
1
111
0
110
1
001
Answer: 1

(ii)

Using decimal -7 = 97, + 6 = 06


Sign Magnitude
9
7
0
6
9
1
Answer: 1

(iii)

Using octal -7 = 77, + 6 = 06


Sign Magnitude
7
7
0
6
7
1
Answer: 1

Signed magnitude system is used in ordinary arithmetic, but is awkward when employed
in computer arithmetic because of the separate handling of the sign and the magnitude.
Therefore, the signed-compliment system is normally used. The design of arithmetic
circuits for sign-and-magnitude binary numbers is difficult.
1.5.2b (r-1)'s Complement Representation:
An n-bit positive number (P) is represented in the same way as in the Sign-andMagnitude representation.The sign bit (MSB) = 0.The remaining n-1 bits represent the
magnitude.
An n-bit negative number (N) is represented using the (r-1)'s Complement of the
equivalent positive number (P) can be represented as.
(r -1)' compliment (r n - r -m ) - P
Where n is the number of integer digit and m number of fraction digit. If the number
having only integer part then the (r-1)s compliment can be represented as:
(r -1)' compliment (r n -1) - P
12

1.5.2c rs Complement Representation


An n-bit positive number (P) is represented in the same way as in the Sign-andMagnitude representation.The sign bit (MSB) = 0.The remaining n-1 bits represent the
magnitude.An n-bit negative number (N) is represented using the r's Complement of
the equivalent positive number (P).
rs complement of any number can be represented as.
r' s compliment (r n - r -m ) - P 1
Where n is the number of integer digit and m number of fraction digit. If the number
having only integer part then the rs compliment of that number can be represented as:
r' s compliment (r n -1) - P 1 r n - P
Table 10, shows the rules for subtraction by addition methods using negative number in
(r-1)s / rs Complement form.
compliments
Carry
(r-1)s compliment Called End Around Carry,
added to the LSB of the sum
output. Answer is positive.
rs compliment
Ignore carry.
Answer is positive.

No carry
Answer is negative with
(r-1)s compliment of the sum
output.
Answer is negative with
rs compliment of the sum
output.
Table 10:(r-1)s / rs Complement Subtraction

1.5
Binary arithmetic:
In this lesson, we'll explore the techniques used to perform simple arithmetic functions on
binary numbers, since these techniques will be employed in the design of electronic
circuits to do the same. You might take longhand addition and subtraction for granted,
having used a calculator for so long, but deep inside that calculator's circuitry all those
operations are performed "longhand," using binary numeration. To understand how that's
accomplished, we need to review to the basics of arithmetic.
1.6.1 Binary Addition:
Adding binary numbers is a very simple task, and very similar to the longhand addition of
decimal numbers. As with decimal numbers, you start by adding the bits (digits) one
column, or place weight, at a time, from right to left. Unlike decimal addition, there is
little to memorize in the way of rules for the addition of binary bits:
Inputs
Outputs
augend addend carry
sum
0
0
1
1

0
0
0
1
1
0
0
1
0
1
0
1
Table 8: Binary addition
Consider the following examples:
(10001)2
+ (10011)2
(100100)2

13

The addition problem on the left did not require any bits to be carried, since the sum of
bits in each column was 1 or 0, not 10 or 11. In the other two problems, there definitely
were bits to be carried, but the process of addition is still quite simple.
1.6.2 Binary Subtraction:
As we'll see later, there are ways that electronic circuits can be built to perform this very
task of addition, by representing each bit of each binary number as a voltage signal
(either "high," for a 1; or "low" for a 0). This is the very foundation of all the arithmetic
which modern digital computers perform.
With addition being easily accomplished, we can perform the operation of subtraction
with the same technique simply by making one of the numbers negative.
Inputs
Outputs
minuend subtrahend borrow
difference
0
0
0
0
0
1
1
1
1
0
1
0
1
1
0
0
Table 9: Binary subtraction
For example, the subtraction problem of 7 - 5 is essentially the same as the addition
problem 7 + (-5). Since we already know how to represent positive numbers in binary, all
we need to know now is how to represent their negative counterparts and we'll be able to
subtract.
Explanations
A= 6
=110
We starts from LSB: substrate 1 from 0
= 1 difference and 1 borrow. Taking borrow:
-B = -5
= 101
Next two bit 11 becomes to 10.Again,
Subtract 0 from 0 = 0difference and 0
borrow.Last, MSB Subtract 0 from 0 =
0difference and 0 borrow.
Result
= (001)2
Verified
1.6.2a Two's Complement Subtraction
A B = A + (-B)
Subtraction can be implemented using addition.Determine the Two's Complement
representation for the negative number -B.Use Two's Complement Addition to add A and
-B.
(i)Carry:
A= 6
-B = -5

Result
Answer
(ii) No carry:
A= 5

=110
= 011

= (1001)2
= + 001

Explanations
*[2s compliment of 101
= 1s compliment of 101+1
=010+1=011]
(1001)2
{Ignore carry: answer is positive}

=101

Explanations
14

-B = -6

=010

Result
Answer

= (111)2
= - 001

*[2s compliment of 110


= 1s compliment of 110+1
=001+1=010]
= (111)2
{no carry: Negative answer}with
[2s compliment of 111
=000+1=001]

1.6.2b One's Complement Subtraction


Instead of discarding the carry from the sign position (MSB), it must be added to the least
significant bit (LSB) of the n-bit sum. Referred to as an end-around carry(EAC)..
Following table summarizes the compliments arithmetic:
(i)Carry:
A = 6 =110
Explanations
-B = -5
=010
For negative number:
*[1s compliment of 101
= 010]
Result
= (1000)2
=(1000)2
{EAC, add carry to LSD}
Answer = + 001
(ii) No carry:
A= 5
-B = -6

=101
=001

Result

= (110)2

Answer

= - 001

Explanations
For negative number:
*[1s compliment of 110
= 001]
= (110)2
{no carry-Answer is negative}with [1s
compliment of 110:
= 001]

1.6
Octal arithmetic:
Because binary numeration requires so many bits to represent relatively small numbers
compared to the economy of the decimal system, analyzing the numerical states inside of
digital electronic circuitry can be a tedious task. Computer programmers who design
sequences of number codes instructing a computer what to do would have a very difficult
task if they were forced to work with nothing but long strings of 1's and 0's, the "native
language" of any digital circuit. To make it easier for human engineers, technicians, and
programmers to "speak" this language of the digital world, other systems of placeweighted numeration have been made which are very easy to convert to and from binary.
One of those numeration systems is called octal, because it is a place-weighted system
with a base of eight. We wont discuss this base system in this document; rather we will
concentrate on the hexadecimal system.
1.7.1 Octal Addition:
Adding octal numbers is a very simple task, and very similar to the longhand addition of
decimal numbers. As with decimal numbers, you start by adding the bits (digits) one
column, or place weight, at a time, from right to left. Unlike decimal addition, there is
little to memorize in the way of rules for the addition of binary bits:
15

Inputs
Outputs
addend
carry octal sum
0
0
0
1
0
1
2
0
3
3
0
5
4
0
7
5
1
1
6
1
3
7
1
5
Table 11: Octal addition
Just as with decimal addition, when the sum in one column is a two-digit number, the
least significant figure is written as part of the total sum and the most significant figure is
"carried" to the next left column. Consider the following examples:
augend
0
0
1
2
3
4
5
6

0ctal
(456)8

decimal
Explanations
302
We start from LSD: add 6 to 3 =(9) 10= (11)8
= octal sum=1 with carry 1.
Add this carry to next digit
(+123)8 +83
= previous carry (1) +5 + 2= (8)10= (10)8
= octal sum =0 with carry 1. Last digit MSD
= previous carry (1) + 4+ 1= 6
Result (601)8 = 385
Verified
1.7.2 OctalSubtraction:
As we'll see later, there are ways that electronic circuits can be built to perform this very
task of addition, by representing each digit of each octal number as a voltage signal.
Inputs
Outputs
subtrahend borrow difference
0
0
0
1
8
1
2
8
7
3
8
7
4
8
7
5
8
7
6
8
7
7
8
7
1
8
9
2
0
1
2
0
2
2
0
3
1
0
5
1
0
6
Table 12: Octal Subtraction
With addition being easily accomplished, we can perform the operation of subtraction
with the same technique simply by making one of the numbers negative For example, the
subtraction problem of 7 - 5 is essentially the same as the addition problem 7 + (-5).
minuend
0
0
1
2
3
4
5
6
2
3
4
5
6
7

16

Since we already know how to represent positive numbers in binary, all we need to know
now is how to represent their negative counterparts and we'll be able to subtract.
0ctal
(75)8

decimal
61

(-66)8

-54

Result (7)8

Explanations
We start from LSD: substrate 6 from 5
(cannot substrate) take borrow fromnext
digit (8+5= 15, subtract 6 from 15= 7).
Next digit7 becomes to 6.Again, Subtract 6
from 6 = 0 difference and 0 borrow.

=7

1.7.2a Eight 's Complement Subtraction


A B = A + (-B)
Subtraction can be implemented using addition.Determine the Two's Complement
representation for the negative number -B.Use Eight's Complement Addition to add A
and -B.
(i)Carry:
A= 6
-B = -5

=6
=3*

Result
Answer

= (9)10
= +1

(ii) No carry:
A= 5
-B = -6
Result
Answer

=5
=2*
= (7)10
= -1

Explanations
*[8s compliment of 5
= 81-5=(3)8]
=(11)8
{Ignore carry}

Explanations
*[8s compliment of 5
= 81-6=(2)8]
= (7)8 {no carry means negative
answer}with
[8s compliment of 7 = 81-7=(1)8]

1.7.2b Seventh's Complement Subtraction


Instead of discarding the carry from the sign position (MSB), it must be added to the least
significant bit (LSB) of the n-bit sum. Referred to as an end-around carry(EAC).
(i)Carry:
A= 6
=6
Explanations
-B = -5
=2*
For negative number:
[7s compliment of 5
= (81-1)-5=(2)8]
Result
= (8)8
=(10)8
{EAC, add carry to LSD}
Answer
= +1
(ii) No carry:
A= 5
-B = -6

=5
=1*

Explanations
For negative number:
17

Result
Answer

= (6)8
= -1

*[7s compliment of 6
= (81-1)-6=(1)8]
= (6)8
{no carry-Answer is negative}with
[7s compliment of E:
= (81-1)-6 = (1)16]

1.7
Decimal arithmetic: the representation of signed decimal number in BCD is
similar to the representation of signed number in binary
1.8.1 Decimal Addition:
Adding decimal numbers is a very simple task, and very similar to the longhand addition
of decimal numbers. As with decimal numbers, you start by adding the digits one
column, or place weight, at a time, from right to left. Unlike decimal addition, there is
little to memorize in the way of rules for the addition of binary bits:
decimal
Explanations
327
We start from LSD: add 3 to 7 = (10) 10
= decimal sum=0 with carry 1.
Add this carry to next digit
+283
= previous carry (1) +8 + 2= (11)10
=decimal sum=1 with carry 1. Last digit MSD
= previous carry (1) + 2+ 3= (6)10
Result = 610
Just as with decimal addition, when the sum in one column is a two-digit number, the
least significant figure is written as part of the total sum and the most significant figure is
"carried" to the next left column. Consider the following examples: In the other two
problems, there definitely were bits to be carried, but the process of addition is still quite
simple.
1.8.2 DecimalSubtraction:
As we'll see later, there are ways that electronic circuits can be built to perform this very
task of addition, by representing each bit of each binary number as a voltage signal
(either "high," for a 1; or "low" for a 0). This is the very foundation of all the arithmetic
which modern digital computers perform.
With addition being easily accomplished, we can perform the operation of subtraction
with the same technique simply by making one of the numbers negative.
For example, the subtraction problem of 7 - 5 is essentially the same as the addition
problem 7 + (-5). Since we already know how to represent positive numbers in binary, all
we need to know now is how to represent their negative counterparts and we'll be able to
subtract.
Usually we represent a negative decimal number by placing a minus sign directly to the
left of the most significant digit, just as in the example above, with -5.
1.8.2a Ten's Complement Subtraction
A B = A + (-B)
Subtraction can be implemented using addition. Determine the Two's Complement
representation for the negative number -B. Use Ten's Complement Addition to add A and
-B.
18

(i)Carry:
A= 6
-B = -5

=6
=5*

Result
Answer

= (11)10
= +1

(ii) No carry:
A= 5
-B = -6
Result
Answer

=5
=4*
= (9)10
= -1

Explanations
*[10s compliment of 5
= 101-5= (5)10]
=(11)1o
{Ignore carry}

Explanations
*[10s compliment of 6 = 101-6=(4)10]
= (9)10
{no carry: Answer will negative}with
[10s compliment of 9 = 101-9=(1)16]

1.8.2b Nine's Complement Subtraction


Instead of discarding the carry from the sign position (MSB), it must be added to the least
significant bit (LSB) of the n-bit sum. Referred to as an end-around carry.
(i)Carry:
A= 6
=6
Explanations
-B = -5
=4*
For negative number:
*[9s compliment of 5
= (101-1)-5=(4)10]
Result
= (10)10
=(10)10
{EAC, add carry to LSD}
Answer = +1
(ii) No carry:
A= 5
-B = -6

1.8

=5
=3*

Result

= (8)10

Answer

= -1

Explanations
For negative number:
*[9s compliment of 6
= (101-1)-6=(3)10]
= (8)10
{no carry: negative answer}with
[9s compliment of 8:
= (101-1)-8 = (1)10]

Hexadecimal Arithmetic:

The hexadecimal system is a place-weighted system with a base of sixteen. Valid ciphers
include the normal decimal symbols 0, 1, 2, 3, 4, 5, 6, 7, 8, and 9, plus six alphabetical
characters A, B, C, D, E, and F, to make a total of sixteen. As you might have guessed
already, each place weight differs from the one before it by a factor of sixteen.
1.9.1 Hexadecimal Addition:
Adding hexadecimal numbers is not a very simple task, and very similar to the longhand
addition of octal numbers. As with decimal numbers, you start by adding the digit one
19

column, or place weight, at a time, from right to left. Unlike decimal addition, there is
little to memorize in the way of rules for the addition of binary bits:
Inputs
Outputs
augend Addend
carry octal sum
0
0
0
0
0
1
0
1
1
2
0
3
2
3
0
5
3
4
0
7
4
5
1
1
5
6
1
3
6
7
1
5
Table 13: Hexadecimal addition
Just as with decimal addition, when the sum in one column is a two-bit (two-digit)
number, the least significant figure is written as part of the total sum and the most
significant figure is "carried" to the next left column. Consider the following examples:
Hexadecimal decimal
Explanations
(26)16
38
We start from LSD: add 6 to 3 = (9) 10= (9)16
= hexadecimal sum=9 with carry 0.
Add this carry to next digit
(+23)16
+35
= previous carry (0) +2 + 2= (4)10= (4)16
Result (49)16
= 73
Verified

1.9.2 HexadecimalSubtraction:
As we'll see later, there are ways that electronic circuits can be built to perform this very
task of addition, by representing each bit of each binary number as a voltage signal
(either "high," for a 1; or "low" for a 0). This is the very foundation of all the arithmetic
which modern digital computers perform.
With addition being easily accomplished, we can perform the operation of subtraction
with the same technique simply by making one of the numbers negative.

Minuend
0
0
1
2
3
4
5
6
2
3
4
5
6

Inputs
subtrahend
0
1
2
3
4
5
6
7
1
2
2
2
1

borrow
0
F
F
F
F
F
F
F
F
0
0
0
0

Outputs
difference
0
1

1
2
3
5
20

1
0
6
Table 14: Signed octal Number
For example, the subtraction problem of 7 - 5 is essentially the same as the addition
problem 7 + (-5). Since we already know how to represent positive numbers in binary, all
we need to know now is how to represent their negative counterparts and we'll be able to
subtract.
Usually we represent a negative decimal number by placing a minus sign directly to the
left of the most significant digit, just as in the example above, with -5. However, the
whole purpose of using binary notation is for constructing on/off circuits that can
represent bit values in terms of voltage (2 alternative values: either "high" or "low"). In
this context, we don't have the luxury of a third symbol such as a "minus" sign, since
these circuits can only be on or off (two possible states). One solution is to reserve a bit
(circuit) that does nothing but represent the mathematical sign:
Hexadecimal decimal
(22)16
34
(-13)16

Result (F)16

-19

= 15

Explanations
We start from LSD: substrate 3 from 2
(cannot substrate) take borrow from next
digit (16+2= 18, subtract 3 from 18= 15).
Next digit 2 becomes to 1.Again, Subtract
1 from 1 = 0 difference and 0 borrow.
Verified

1.9.2a Sixteen's Complement Subtraction


A B = A + (-B)
Subtraction can be implemented using addition.Determine the Two's Complement
representation for the negative number -B.Use Sixteen's Complement Addition to add A
and -B.

(i)Carry:
A= 6
-B = -5
Result
Answer

=6
=11*
= (17)1
= +1

Explanations
[16s compliment of 5 = 161-5=(11)16]
=(11)16
{Ignore carry}

(ii) No carry:
A= 5
-B = -6

=5
=10*

Explanations
*[16s compliment of 5
= 161-5=(11)16]
= (F)16 {Carry-Ans. Negative}with
[16s compliment of F = 161-15=(1)16]

Result
Answer
Answer

= (15)10
= -1
= -1

1.9.2b Fifteen's Complement Subtraction


Instead of discarding the carry from the sign position (MSB), it must be added to the least
significant bit (LSB) of the n-bit sum. Referred to as an end-around carry.
21

(i)Carry:
A= 6
-B = -5

=6
=10*

Result
Answer

= (16)10
= +1

(ii) No carry:
A= 5
-B = -6
Result
Answer

=5
=9*
= (14)1
= -1

Explanations
[15s compliment of 5
= (161-1)-5=(11)16]
=(10)16
{EAC, add carry to LSD}

Explanations
*[15s compliment of 5 = 161-5=(11)16]
= (E)16
{no carry-Answer is negative}with
[15s compliment of E:
= (161-1)-14 = (1)16]

1.9
Binary codes
Computers work with binary numbers. The signals in most present-day electronic digital
systems use just two discrete values and are therefore said to be binary. A binary digit,
called bit, has two values: 0 and 1. Each coefficient is multiplied by 2n where n is the
position of bit. Discrete elements of information are represented with groups of bits
called binary codes. The binary system is a different number system. The binary number
is a string of zeros and ones. Since it has only two digits, the base is 2.
An n-bit binary code is a group of n bits that assumes up to 2n distinct combinations of
1s and 0s, with each combination representing one element of the set that is being
coded. A set of four elements can be coded with two-bits, with each element assigned one
of the following bit combinations: 00, 01, 10, and 11. A set of eight elements requires a
three-bit code and a set of 16 elements requires a four-bit code.
Although the minimum number of bits required to code 2n distinct quantities is n, there is
no maximum number of bits that may be used for a binary code. For example, the 10
decimal digit can be coded with 10 bits, and each decimal digit can be assigned a bit
combination of nine 0s and 1. In this particular binary code, the digit 6 is assigned the
bit combination 0001000000.
In binary system the positive and negative numbers may be represented as (i) signed
magnitude, and (ii) 1s complement and 2s complement.
In order to represent the 16 decimal digits, 0 through 15, in binary code, it is necessary to
use at least 4-bit binary numbers (0 = 0000 and 15 = 1111). Since there are sixteen
combinations of four binary digits, it is possible to form a very large number of distinct
codes.
There are of two types of binary code namely Weighted and Unweighted. A weighted
code is one in which each position in the code has a specific weight. Aunweighted code is
one in which the positions in the code do not have a specific weight. Lets assume a 4-bit
weighted code havingWeights: w3, w2, w1, w0and Code: a3a2a1a0 their Decimal (D)
equivalent:
D = a3 x w3 + a2 x w2 + a1 x w1 + a0 x w0
1.9.1

Binary Coded Decimal (BCD) or 8421 code:

22

It is a 4-bit binary number weighted code used to represent each decimal digit.
The binary values from 0000 to 1001 are valid code used to represent the decimal
digits 0 to 9. The binary values 1010 to 1111 are invalid not used (unused).
1.9.2

2-4-2-1 Code
Weighted code with w3 = 2, w2 = 4, w1 = 2, w0 = 1

1.9.3

Excess-3 Code
Obtained from the 8-4-2-1 (weighted code).
Add 3 (00112) to each of the codes.

1.9.4

2-out-of-5 Code
Unweighted code
Exactly 2 of the 5 bits are 1 for each valid code. Following tables summarizes
the different binary codes.
Four Different Binary Codes for the Decimal Digit
Decimal Digit BCD 8421
2421
Excess-3
0
0000
0000
0011
1
0001
0001
0100
2
0010
0010
0101
3
0011
0011
0110
4
0100
0100
0111
5
0101
1011
1000
6
0110
1100
1001
7
0111
1101
1010
8
1000
1110
1011
9
1001
1111
1100
Unused
bit 1010
0101
0000
combinations
1011
0110
0001
1100
0111
0010
1101
1000
1101
1110
1001
1110
1111
1010
1111
2 Table 15: Different binaryCodes

8,4,-2,-1
0000
0111
0110
0101
0100
1011
1010
1001
1000
1111
0001
0010
0011
1100
1101
1110

1.10.4 Gray Code(s)


Unweighted code, Code values for successive decimal digits differ in exactly one
bit.
Decimal 3-bit Gray Code
4-bit Gray Code
G2
G1
G0
G3
G2
G1
G0
0
0
0
0
0
0
0
0
1
0
0
1
0
0
0
1
2
0
1
1
0
0
1
1
3
0
1
0
0
0
1
0
4
1
1
0
0
1
1
0
5
1
1
1
0
1
1
1
6
1
0
1
0
1
0
1
7
1
0
0
0
1
0
0
23

8
9
10
11
12
13
14
15

1
1
1
1
1
1
1
1
Table 16: 3-bit, 4-bit Gray Code

1
1
1
1
0
0
0
0

0
0
1
1
1
1
0
0

0
1
1
0
0
1
1
0

1.10.5 ASCII Code


American Standard Code for Information Interchange. Common code used for the
storage and transfer of alphanumeric characters. 7-bit Weighted Code. Can
represent a total of 128 characters.Used to represent letters, numbers and other
characters (e.g. special control characters). Any word or number can be
represented (and stored or transferred) using its ASCII Code.
Table 17: American Standard Code for Information Interchange (ASCII)
b4b3b2b1
b7b6b5
000
001
010
011
100
101
110
111
NUL DLE SP
0
@
P
`
p
0000
SOH DC1 !
1
A
Q
A
q
0001
STX
DC2

2
B
R
B
r
0010
ETX DC3 #
3
C
S
C
s
0011
EOT DC4 $
4
D
T
D
t
0100
ENQ NAK %
5
E
U
E
u
0101
ACK SYN &
6
F
V
F
v
0110
BEL EDP
7
G
W
G
w
0111
BS
CAN (
8
H
X
H
x
1000
HT
EM
)
9
I
Y
I
y
1001
LF
SUB *
:
J
Z
J
z
1010
VT
ESC +
;
K
[
K
{
1011
FF
FS
,
<
L
L
1100
\
|
CR
GS
=
M
]
M
}
1101
SO
RS
.
>
N
N
~
1110
^
SI
US
/
?
O
O
DEL
1111

Control Character:
NUL
Null
SOH
Start of heading
STX
Start of text
ETX
End of text
EOT
End of transmission
ENQ
Enquiry
ACK
Acknowledge
BEL
Bell
BS
Backspace
HT
Horizontal tab

DLE
DC1
DC2
DC3
DC4
NAK
SYN
EDP
CAN
EM

Data-link escape
Device control 1
Device control 2
Device control 3
Device control 4
Negative acknowledge
Synchronous idle
End-of-transmission block
Cancel
End of medium
24

LF
VT
FF
CR
SO
SI
SP

Line feed
Vertical tab
Form feed
Carriage return
Shift out
Shift in
Space

SUB
ESC
FS
GS
RS
US
DEL

Substitute
Escape
File separator
Group separator
Record separator
Unit separator
Delete

1.10.6 Error correcting and detecting codes:


It is physically impossible for any data recording or transmission medium to be
100% perfect 100% of the time over its entire expected useful life.As more bits
are packed onto a square centimeter of disk storage, as communications
transmission speeds increase, the likelihood of error increases-- sometimes
geometrically.Thus, error detection and correction is critical to accurate data
transmission, storage and retrieval.
Data that is either transmitted over communication channel (e.g. bus) or stored in
memory is not completely error free.Thus, to provide data integrity over the long
term, error correcting codes are required.
Hamming codes and Reed-Soloman codes are two important error correcting
codes.
Reed-Soloman codes are particularly useful in correcting burst errors that occur
when a series of adjacent bits are damaged.Because CD-ROMs are easily
scratched, they employ a type of Reed-Soloman error correction. Because the
mathematics of Hamming codes is much simpler than Reed-Soloman, we discuss
Hamming codes in detail.Hamming codes are code words formed by adding
redundant check bits, or parity bits, to a data word.Error can cause by:
1.10.6a Transmission Errors:Signal distortion or attenuatione.g. sender and
receiver out of synchronous, can happen if clocks are not synchronized systems
distributed over network
1.10.6b Storage Errors:DRAM memory cell contents can change spuriously due
to some Electromagnetic interference n magnetic storage devices such as disks,
magnetic flux density ncreases could cause one or more bits to flip (change that
value)Error detection is the ability to detect errors. Error correction has an
additional feature that enables identification and correction of the errors. Error
detection always precedes error correction. Both can be achieved by having extra
or redundant or check bits in addition to data deduce that there is an error. Original
Data is encoded with the redundant bit(s). New data formed is known as code
wordParity
1.10.6c the simplest and oldest error detection method:
In this scheme, a binary digit called parity is used to indicate whether the number
of bits with value of one in a given set of bits is even or odd and is appended to
original data. Usually used to detect transmission error.The sender adds the parity
bit to existing data bits before transmission.The receiver checks for the expected
parity, if wrong parity found, the received data is discarded and retransmission is
requested
Parity type: Even

25

Forced an even number of ones on total data sent000 0001 (total number of 1 is 1
i.e., odd) add 1 in the MSB 1
000 0001 to make it even. Generating even
parity bit is just an XOR function.
Check Data Received Examples 01111111 - incorrect, 1000 0000
incorrect,1000 0001 - valid
Note that error could be in data or parity
Not entirely fool proof
Parity type: Odd
Forced an odd number of ones000 0001 (total number of 1 is 1 i.e., odd) add 0
in the MSB 0000 0001 to make it odd. Odd parity is generated using a XNOR
function.
Limitations of Parity
Data Word
Parity Code
Code word
(Even)
00
0
000
01
1
011
10
1
101
11
0
110
Two data and one parity (3 bit) 8 possible combinations, only 4 correct codewords, Cannot determine which bit position has a problem. If 001 is encountered,
it is not a valid code-word and hence error is detected. The correct code-word
could either be 101 or 011 but we cannot tell
000
100
001
101
010
110
011
111
What happens if the code word is subjected to two-bit error?E.g. 011 became 000
while transmission. According to parity scheme, no error is detected but error!!
In general, if an odd number of bits (including the parity bit) are changed from a
set of bits then parity bit will be incorrect and will thus indicate that an error has
occurred
1.10.7 Hamming Code (HC):
Hamming Code is type of Error Correcting Code (ECC), provides error detection
and correction mechanism. Adopt parity concept, but have more than one parity
bit. In general hamming code is code word of n bits with mdata bits and r
parity (or check bits)i.e. n = m + r, can detect {D (min) 1} error, and correct
D (Min ) 1

errors. Hence to correct k errors, need D (min) = 2k + 1, you need a


2

least a distance of 3 to correct a single bit error.Thus, a Hamming distance of 2k +


1 is required to be able to correct k errors in any data word.
Hamming distance is provided by adding a suitable number of parity bits to a data
word. It is well known for its single-bit error detection and correction capability.
Its based on the adding of r parity (redundancy) bits to m data bus such that:
2rm + r + 1, 2r-1 bits: hammingCode, r: parity (redundancy) bits, (2r-1) - r: data
26

bits. After error detection and correction, if any, the data bits have to be
reassembled by removing the redundancy bits.
Hamming code is normally used for transmission of 7-bit data item. Scaling it for
larger data lengths results in a lot of overhead due to interspersing the parity bits
and their removal later.
Hamming Distance and Error Detection: The Hamming distance between two
code words is the number of bits in which two code words differ.This pair of
bytes has a Hamming distance 3:

Hamming Distance is equal to the number of bit positions in which two code
words differ or XOR of this pair of bytes then count total numbers of 1 is the
Hamming distance. The minimum Hamming distance for a code is the smallest
Hamming distance between all pairs of words in the code.The minimum
Hamming distance for a code, D(min), determines its error detecting and error
correcting capability.
Suppose we have a set of n-bit code words consisting of m data bits and r
(redundant) parity bits.
An error could occur in any of the n bits, so each code word can be associated
with n erroneous words at a Hamming distance of 1. For example 10001001 and
10110001 have distance of 3,
If hamming distance is d apart, then d-single bit errors are required to convert any
one valid code into another. Implying that this error would not be detected.
In previous parity example (slide 7), Could detect 1-bit error as 4 code words had
hamming distance = 2, But could not detect 2-bit error.
In general, to detect k-single bit error, minimum hamming distance D(min) =k + 1
Hence we need code words that have D(min) = 2 + 1 = 3 to detect 2-bit errors. If
there is a larger hamming distance between valid code words, then we may be
able to determine which valid codeword was intended. Suppose a code needs just
2 different values, and we use:One valid value = 0000 0000 and the other = 1111
1111. Then distance between these is 8.
Suppose we got 2 bit changes so that:0000 0000 became 0011 0000, Can we
determine what the transmitted value was?Was it more likely 0000 0000 or 1111
1111?
The greater the distance between valid code words, the easier it is to figure what
the correct codeword was requires additional redundant bits (> 1 parity bit) to
choose code words that are far apartD (min) = 2k + 1 is required for correcting kerrors.
Determining number of Parity bits for single-bit correction: Hamming Code
for single-bit error correction is the most commonly usedExperiments (IBM
study) show 98% time there are single-bit errors, Need determine r for m-data bits
that provides code words of n-bits that has single-bit correction capabilities.
An error could occur in any of the n bits of the code word, so each code word can
be associated with erroneous words (at a hamming distance of 1)E.g. Previous
Parity Example (slide 7)
27

000 can become 001 or 010 or 100 due to single bit errorTherefore, we have n + 1
bit patterns for each code word: one valid code word, and n erroneous words. This
gives us the inequality: (n + 1) 2 m 2n where 2 m is the number of legal code
Hamming Code: Determining Parity bits for single-bit correction
Because n = m + r, we can rewrite the inequality as:
(m + r + 1) 2 m 2 m+ ror (m + r + 1) 2r
This inequality gives us a lower limit on the number of parity bits that we need in
our code words.
Example: Suppose we have data words of length m = 4
(4 + r + 1) 2r
Implies that r must be greater than or equal to 3. This means to build a code with
4-bit data words that will correct single-bit errors; we must add 3 check bits.
Example: Generation of 12-bit Code word
Number of parity bits: if the number of information bits is designated m then the
number of parity bits, r is determines by the following relationship:
(m + r + 1) 2 m 2 m + r
Or (m + r + 1) 2 r
8-bit data needs 4 parity bits, total of 12-bit code word, using our code words of
length 12, number each bit position starting with 1 in the low-order bit. Each bit
position corresponding to an even power of 2 will be occupied by a parity or
check bit. All other bit positions are for the data to be encoded. This means to
build a code with 8-bit data words that will correct single-bit errors, we must add
4 check bits, creating code words of length 12.
Bit Designation
P1
P2
TD
3
T
P4
aD
5
bD
6
lD
7
e
P8
D9
1D
10
8D
11
:D
12

Bit Position
1
2
3
4
5
6
7
8
9
10
11
12

Binary Position Number


P8 (23)
P4 (22)
P2 (21)
0
0
0
0
0
1
0
0
1
0
0
1
0
0
1
0
1
1
0
1
1
0
0
1
0
0
1
0
1
1
0
1
1
0
1
1

P1 (20)
1
0
1
0
1
0
1
0
1
0
1
0

Placement of the parity bits in the code


The parity bits are located in the positions that are numbered corresponding to
ascending powers of two.Notice that the binary position number of parity bit P1
has 1 for its column. This parity bit checks all bit positions including itself, that
have 1s in the same location (column) in the binary position numbers. Therefore,
Parity Bit P1checks the bit positions: 1, 3, 5, 7, 9, and 11.
Parity Bit P2checks the bit positions: 2, 3, 6, 7, 10, and 11.
28

Parity Bit P4checks the bit positions: 4, 5, 6, 7, and 12.


Parity Bit P8checks the bit positions: 8, 9, 10, 11, and 12.
Each parity bit calculates the parity for some of the bits in the code word

Error Correcting Codes (ECC) in General


Hamming Code is type of ECC,Others include Reed-Solomon, Convolution Code
Requires extra bits for maintaining information integrity
E.g. in hamming code: 3 bits are added to a 4-bit data
The overhead of extra bits does pay off
Single-bit correction often costs less than sending the entiredata twice
If the storage is the only source of data (e.g. disk or DRAM) then we want a errorcorrection to avoid crashing of programs

1.11 Industrial application of number system and code

29

Number system at a glance


There are two input signals: analog signals have infinite number of distinct values and are continuous,
while digital signals have finite number of distinct values and are discrete in nature.

Types of number systems are : decimal, binary, octal, hexadecimal.


Codes are representation if digital in specified format which include symbols, alphabets etc.
There are two logic levels in digital system : high (1) and low (0).
There are two logic systems positive and negative.
Number system is a set of rules and symbols to represent numbers. It can be weighted or nonweighted.
Number of values that a character or digit can assume is called Radix or Base.
Decimal system has radix 10. Leftmost digit is MSD and rightmost digit is LSD.
Binary system has radix 2 and two binary digits one 1 and 0. Its weight is expressed as a power
of 2.
The smallest unit of information is called bit (0 and 1).
Binary representation of four bits is called a Nibble.
A byte is a combination of 8-binary bits.
A word is a combination of 16-binary bits.
Octal numbers system has radix 8 and the digits are (0 to 7). Its weight is expressed in power of 8.
Hexadecimal has radix 16. The digits are 0 to 9 in continuation with letters A to F Its weight is
expressed in power of 16.
ls complement of a binary number is written by simply replacing all 0s by 1 and all 1s by 0.
2s complement is one increment of ls complement.
Numbers without +ve / -ve sign are unsigned numbers.
Numbers represented by sign magnitude are signed numbers.
BCD represent as 4 bit binary code; also known as 8421 code.
Gray codes are reflected codes in which the successive coded characters differ in only bit position.
Alphanumeric codes are represented by letters, symbols and numbers. These are ABC codes,
EBCDIC codes and ASCII code.

30

Problems
1.1.1
1.1.2
1.1.3
1.1.4

1.1.5
1.1.6
1.1.7
1.1.8
1.1.9
1.1.10
1.1.11
1.1.12
1.1.13
1.1.14
1.1.15
1.1.16
1.1.17
1.1.18
1.1.19
1.1.20

1.1.21

1.1.22
1.1.23

1.1.24
1.1.25

What is number system? What are its types? Give example for each type of number system.
Convert the binary number (110)2 to its decimal equivalent.
Convert the binary number (1011.01) to its decimal equivalent.
Convert the following:
(521.63)8 to the base 10 and vice versa.
(11011.111)2 to the base 10 and vice versa.
(2B.48)16 to the base 10 and vice versa.
(0.6875)10 to the base 2 and vice versa.
(305.6875)10 to the base 8 and vice versa.
(7825.760) 10 to the base 16 and vice versa.
(0.1011011) 2 to the base 8 and vice versa.
(10110110.101111001)2 to the base 16 and vice versa.
(436) 8 to the base 16 and vice versa.
(1AF)16 to the base 8 and vice versa.
(68.4B) 16 to the base 8 and vice versa.
What is the largest decimal number that can be represented by a 16 bit binary word?
Define bit, byte and nibble.
Find the complement of AB B C CD .
What do you mean by weighted code? Give example.
Represent the decimal number 8620 in BCD and as a binary number.
List the advantages of octal over hexadecimal number system.
What is the use of (r-1)s and rs compliment in digital electronics? What do you think about
(r-n)s compliment where n = 2, 3, 4, 5, 6, 7, 8, 9?
Find twos complement of the numbers (i) 01001110 ; (ii) 01100100.
What is the need to study octal and hexadecimal system, when the Digital machine
understands only binary code?
Where do we use ASCII, Excess-3 and Gray codes?
Determine the decimal representation of a negative integer whose 8-bit twos complement
code is 10010110.
Give the binary code for the hexadecimal number AEO.
How negative numbers are accounted for in digital system?
Give the binary code for the hexadecimal number F01.
Determine the decimal representation of a negative integer whose 8bit twos complement
code 10010110.
Subtract the following numbers using different techniques.
(i) (1100.10)2 (111.01)2
(ii) (10001.01)2 (1111.11)2
Add the following numbers in Excess - 3 Code.
(i) 108 + 789
(ii) 275 + 496
Subtract the following numbers
(i) (BC5)16 (A2B)16 (ii) (1 75.6)8 (47.7)8
Add the following numbers in BCD
(i) 89.6 + 273.7
(ii) 205.7 + 193.65
How will you detect overflow in signed magnitude and 2s complement integer additions?
What are the applications of hexadecimal system? Perform the following conversions
(a) (225225) 10 into hexadecimal number.
(b) (10011.1101)2 into hexadecimal number.

31

1.1.26 What is the importance and applications of Gray code? Convert the binary number
10100111 to Gray code.
1.1.27 Represent the decimal numbers (a) 27, (b) 396 and (c) 4096 in binary form in (i) ASCII
code, (ii) Gray code and (iii) Excess 3 code.
1.1.28 If A = 1101 and B = 101 find:
(ii)
A+B
(iii)
A-B
(iv)
B-A
(v)
AxB
By 2s complement method.
1.1.29 Find the difference (6C1-1DA) in the hexadecimal system. Check your result converting all
number, i.e. the given two numbers and the result obtained from subtraction to the decimal
system.
1.1.30 In the following expression, find the value of radii x ( x is the positive integer)
(212)x= (23)10
(1000)x=[(11)2]3
1.1.31 A particular brand of CD player has the capacity of converting 12-bit signals from a CD into
their equivalent analog values.

What are the largest and smallest hex value that can be used in this CD system.

How many different analog values can be represented by this system?


1.1.32 Typically, digital thermometer use BCD to drive their displays
(a) How many BCD bits are required to drive a 3-digit thermometer display?
(b) What 12 bits are sent to be the display for a temperature of 147?
1.1.33 In a new number system, A and B are successive digits such that (AB)x=25, and (BA)x=31.
Find A, B, and x.
[{A=3,B=4, and x=7} hints: successive digit means B=A+1]
1.1.34 Instead of using digits0 and 1 for the binary numbers, use A and B, respectively.
Show how to count from 0 to 7.
[{A, B, BA, BB, BAA, BAB, BBA, BBB} hints: ignore MSB 0]
1.1.35 Show how to count a number system with a base 3, use x, y, z instead of 0, 1, 2.
1.1.36 The solution to the quadratic equation x2-11x+22=0 is x=3 and 6. What is the base of the
number?
1.1.37 Construct addition and multiplication tables for base 3.
1.1.38 Nothing that 32=9, formulate a simple procedure for converting base-3 number directly to
base 9 using (21 10 20 11 02 22)3 to base 9.
1.1.39 Consider the following four codes
Code A
Code B
Code C
Code D
0001
000
01011
000000
0010
001
01100
001111
0100
011
10010
110011
1000
010
10101
110
111
101
100
Note: Minimum distance=2: detect single bit error.
Minimum distance = 3: detect double bit error (detect and correct one single error).
Minimum distance=4: detect triple bit error (detect double error and correct single
error).
(a) Which of the following properties is satisfied by each of the above codes?
(i)
Detect single errors. [ A,C,D hints: detect single error-minimum distance=2]

32

(ii)
Detect double errors[ C, and D hints: minimum distance=3, 4]
(iii)
Detect triple error[ D hints: detect minimum distance=4]
(iv)
Correct single errors[C, and D hints: minimum distance= 3, 4]
(v)
Correct double errors[ None hints: minimum distance must be =5]
(vi)
Correct single and detect double errors[ D hints: minimum distance=4]
(b) How many words can be added to code A without changing its error-detection and
correction capabilities? Give possible set of such words. Is this set unique?
[Hints: there are four possible code words that can be added to code A, without
changing it error-detection and correction capability. Those are 1101, 0111, 1011 and
1110. This set is unique.]
1.1.40 Assign a binary code in some orderly manner to the 52 playing cards. Use minimum number
of bits. [ hints: 25=32, 26=64, we need 6 bit]
1.1.41 Find the decimal number whose complement twos complement is 10000000.
1.1.42 Determine the base of the numbers in each case for the following operation to be correct.
(a)

14
302
12.1 , (c)
5 , (b)
20
2

41 5

1.1.43 In the following series, the same integer is expressed in different number systems.
Determine the missing number of the series.
10000, 121, 100, ? , 24, 22, 20

33

Das könnte Ihnen auch gefallen