Number System and Codes
Number System and Codes
Number System and Codes
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.
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)
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
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
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
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)
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)
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)
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)
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)
Grouping
0010.0010
Hexadecimal
2.2
(iv)
1.3.5
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
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)
(iii)
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
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
=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
=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]
=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
=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
(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
(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
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
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
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
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
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
P1 (20)
1
0
1
0
1
0
1
0
1
0
1
0
29
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.
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