IntroductionIntroduction
The term The term digitaldigital is derived from the way is derived from the way
computers perform operation, by counting computers perform operation, by counting
digits.digits.
Application of digital technology: Application of digital technology:
television, communication systems, radar, television, communication systems, radar,
navigation and guidance system, military navigation and guidance system, military
system, medical instrument, industrial system, medical instrument, industrial
process control and etc. process control and etc.
Digital and Analog QuantitiesDigital and Analog Quantities
Analog quantities have continuous valuesAnalog quantities have continuous values
Digital quantities have discrete sets of Digital quantities have discrete sets of
valuesvalues
Analog : a quantity represented by Analog : a quantity represented by
voltage, current or meter movement that is voltage, current or meter movement that is
proportional to the value of that quantityproportional to the value of that quantity
Digital : the quantities are represented not Digital : the quantities are represented not
by proportional quantities but by symbols by proportional quantities but by symbols
called called digits digits
Digital and Analog QuantitiesDigital and Analog Quantities
Analog quantitiesAnalog quantities have have
continuous valuescontinuous values
Digital quantitiesDigital quantities have have
discrete sets of valuesdiscrete sets of values
Advantages of Digital Systems Over Advantages of Digital Systems Over
Analog SystemsAnalog Systems
More reliable than analog systems due to better More reliable than analog systems due to better
immunity to noise & better accuracy. immunity to noise & better accuracy.
Ease of design: No special math skills needed to Ease of design: No special math skills needed to
visualize the behavior of small digital (logic) circuits.visualize the behavior of small digital (logic) circuits.
Programmability.Programmability.
Speed: A digital logic element can produce an output in Speed: A digital logic element can produce an output in
less than 10 nanoseconds (10less than 10 nanoseconds (10
-8-8
seconds). seconds).
Economy: Due to the integration of millions of digital Economy: Due to the integration of millions of digital
logic elements on a single miniature chip forming low logic elements on a single miniature chip forming low
cost integrated circuit (ICs).cost integrated circuit (ICs).
Binary DigitsBinary Digits
The conventional numbering system uses ten The conventional numbering system uses ten
digits: 0,1,2,3,4,5,6,7,8, and 9.digits: 0,1,2,3,4,5,6,7,8, and 9.
The binary numbering system uses just two The binary numbering system uses just two
digits: digits: 00 and and 1.1.
The two binary digits are designated The two binary digits are designated 00 and and 11
They can also be called LOW and HIGH, where They can also be called LOW and HIGH, where
LOW = 0LOW = 0 and and HIGH = 1HIGH = 1
Logic LevelLogic Level
Number Systems, Number Systems,
Operations and CodesOperations and Codes
IntroductionIntroduction
The binary system and digital codes are The binary system and digital codes are
fundamental to computers and to digital fundamental to computers and to digital
electronic in general.electronic in general.
The binary number system such as decimal, The binary number system such as decimal,
hexadecimal and octal is presented.hexadecimal and octal is presented.
Arithmetic operations with binary numbers are Arithmetic operations with binary numbers are
covered to provide a basis for understanding covered to provide a basis for understanding
how computers and many other types of digital how computers and many other types of digital
systems work. systems work.
Number SystemNumber System
0 ~ 90 ~ 9
0 ~ 1 0 ~ 1
0 ~ 70 ~ 7
0 ~ F0 ~ F
DecimalDecimal
BinaryBinary
OctalOctal
HexadecimalHexadecimal
Decimal NumbersDecimal Numbers
In decimal number system each of the ten In decimal number system each of the ten
digits, 0 through 9digits, 0 through 9
Example:
Express the decimal
number 2745.214 as a
sum of the values of
each digit
Binary NumbersBinary Numbers
The binary number system is another way The binary number system is another way
to represent quantities. There are 1 (to represent quantities. There are 1 (HIGHHIGH) )
and 0 (and 0 (LOWLOW))
The binary numbering system has a base The binary numbering system has a base
of 2 with each position weighted by a factor of 2 with each position weighted by a factor
of 2:of 2:
An ApplicationAn Application
Illustration of a Simple Binary Counting Application
Decimal-to-Binary ConversionDecimal-to-Binary Conversion
Sum-of-Weight MethodSum-of-Weight Method
Repeated Division by 2 MethodRepeated Division by 2 Method
Converting Decimal Fractions to BinaryConverting Decimal Fractions to Binary
Sum-of-Weight MethodSum-of-Weight Method
The decimal number 9,
for example, can be
expressed as the sum of
binary weight of:
1 0 0 1
Example:
Convert the following decimal
numbers to binary:
a) 12 b) 25 c) 58 d) 82
1100 11001 111010 1010010
Repeated Division by 2 MethodRepeated Division by 2 Method
0
2
1
1
2
3
3
2
6
6
2
12
1
1
0
0
A systematic method of converting whole numbers from decimal to
binary is the repeated division-by-2 process.
1100
LSBMSB
Stop when the
whole-number
quotient is 0
Remainder
Convert the
decimal number
12 to binary
Convert decimal number
39 to binary?
Converting Decimal Fractions to Converting Decimal Fractions to
BinaryBinary
0.625 = 0.5 + 0.125 = 2
-1
+ 2
-3
= 0.101
0.625 x 2 = 1.25
0.25 x 2 = 0.50
0.50 x 2 = 1.00
Stop
when the
fractional
part is all
zeros
1
0
1
Carry
. 1 0 1
MSB LSB
Binary ArithmeticBinary Arithmetic
Binary arithmetic is essential in all digital Binary arithmetic is essential in all digital
computers and in many other types of computers and in many other types of
digital systems.digital systems.
Addition, Subtraction, Multiplication, and Addition, Subtraction, Multiplication, and
Division Division
Binary AdditionBinary Addition
The four basic rules for adding binary digits (bits) are as follows:
0 + 0 = 0 sum of 0 with a carry of 0
0 + 1 = 1 sum of 1 with a carry 0f 0
1 + 0 = 1 sum of 1 with a carry of 0
1+ 1 = 10 sum of 0 with a carry 0f 1
11
01 1
+ 00 1
10 0
Carry
Try This:
11 + 11 = ??
Binary SubtractionBinary Subtraction
The four basic rules for subtracting bits are as follows:
0 – 0 = 0
1 – 1 = 0
1 – 0 = 1
10 – 1 = 1 0 – 1 with a borrow of 1
1 1 – 0 1 = ??
1 1
- 0 1
1 0
Try This:
1 0 1 – 0 1 1 = ???
Binary MultiplicationBinary Multiplication
The four basic rules for multiplying bits are as follows:
0 X 0 = 0
0 X 1 = 0
1 X 0 = 0
1 X 1 = 1
1 1 X 1 1 = ??
1 1
X 1 1
1 1
+1 1
1 0 0 1
Try This:
1 1 1 X 1 0 1 = ??
Binary DivisionBinary Division
Division in binary follows the same procedure as division in
decimal.
1 1 0 ÷ 11 = ??
1 0
11 1 1 0
1 1
0 0 0
Try This:
1 1 0 ÷ 10 = ??
1’s and 2’s Complements of Binary 1’s and 2’s Complements of Binary
NumbersNumbers
The 1’s and 2’s Complements of Binary The 1’s and 2’s Complements of Binary
Numbers are very important because they Numbers are very important because they
permit the representation of negative permit the representation of negative
numbers. numbers.
The method of 2’s compliment arithmetic The method of 2’s compliment arithmetic
is commonly used in computers to handle is commonly used in computers to handle
negative numbersnegative numbers
Finding the 1’s ComplementFinding the 1’s Complement
The 1’s complement of a binary number is found by
changing all 1s to 0s and all 0s to 1s.
Example:
1 0 1 1 0 0 1 0 (Binary Number)
0 1 0 0 1 1 0 1 (1’s Complement)
NOT Gate
Finding the 2’s ComplementFinding the 2’s Complement
The 2’s complement of a binary number is found by
adding 1 to the LSB of the 1’s complement
Find the 2’s complement of 10110010
10110010 (Binary number)
+01001101 (1’s complement)
1 (Add 1)
01001110
Alternative Method to find 2’s Alternative Method to find 2’s
ComplementComplement
Start at the right with the LSB and write Start at the right with the LSB and write
the bits as they are up and including the the bits as they are up and including the
first 1first 1
Take the 1’s complements of the Take the 1’s complements of the
remaining bits remaining bits
10111000 (Binary Number)
01001000 (2’s Complement)
1’s Complements of original bits
These bits stay the same
Try This:
10010001
01101111
Signed NumbersSigned Numbers
Digital systems, such as the computer, must be able to
handle both positive and negative numbers. A signed binary
number consists of both sign and magnitude information. The
sign indicates whether a number is positive or negative and
the magnitude is the value of the number. There three forms
in which signed integer (whole) numbers can be represented
in binary:
1.Sign-Magnitude
2.1’s Complement
3.2’s Complement
The Sign Bit
The left-most bit in a signed binary number is the sign bit,
which tells you whether the number is positive or negative.
Sign-Magnitude Form
When a signed binary number is represented in sign-
magnitude, the left-most bit is the sign bit and the remaining
bits are the magnitude bits. The magnitude bits are in true
(uncomplemented) binary for both positive and negative
numbers.
Decimal number, +25 is expressed as an
8-bit signed binary number using sign-
magnitude form as:
00011001
Magnitude Bit
Sign Bit
1’s Complement Form
2’s Complement Form
Positive numbers in 1’s complement form are represented
the same way as the positive sign-magnitude numbers.
Negative numbers, however, are the 1’s complements of the
corresponding positive numbers. Example: The decimal
number -25 is expressed as the 1’s complement of +25
(00011001) as (11100110)
In the 2’s complement form, a negative number is the 2’s
complement of the corresponding positive number
Express the decimal number -39 in sign-magnitude, 1’s
complement and 2’s complement
00100111 >>> 10100111
00100111 >>> 11011000
00100111 >>> 11011001
00100111
The Decimal Value of Signed The Decimal Value of Signed
NumbersNumbers
Sign-Magnitude:
Decimal Value of positive and negative
numbers in the sign-magnitude form are
determined by summing the weights in all
the magnitude bit positions where there
are 1s and ignoring those positions where
there are zeros.
Determine the decimal value of this signed binary
number expressed in sign magnitude: 1 0 0 1 0 1 0 1
2
6
2
5
2
4
2
3
2
2
2
1
2
0
0 0 1 0 1 0 1 >> 16 + 4 + 1 = 21
The sign bit is 1: Therefore, the decimal number is -21
The Decimal Value of Signed The Decimal Value of Signed
NumbersNumbers
1’s Complement:Decimal values of negative numbers are
determined by assigning a negative value
to the weight of the sign bit, summing all
the weight where there are 1s and adding
1 to the result
Determine the decimal values of this signed binary
numbers expressed in 1’s complement
00010111 11101000
-2
7
2
6
2
5
2
4
2
3
2
2
2
1
2
0
-2
7
2
6
2
5
2
4
2
3
2
2
2
1
2
0
0 0 0 1 0 1 1 1
16 + 4 + 2 + 1 = +23
1 1 1 0 1 0 0 0
-128 + 64 + 32 + 8 = -24 + 1 = -23
The Decimal Value of Signed The Decimal Value of Signed
NumbersNumbers
2’s Complement:
The weight of the sign bit in a negative
number is given a negative value
Determine the decimal values of this signed binary
numbers expressed in 1’s complement
01010110 10101010
-2
7
2
6
2
5
2
4
2
3
2
2
2
1
2
0
-2
7
2
6
2
5
2
4
2
3
2
2
2
1
2
0
0 1 0 1 0 1 1 0
64 + 16 + 4 + 2 = +86
1 0 1 0 1 0 1 0
-128 + 32 + 8 + 2 = -86
Arithmetic Operations with Arithmetic Operations with
Signed NumberSigned Number
In this section we will learn how signed
numbers are added, subtracted, multiplied and
divided. This section will cover only on the 2’s
complement arithmetic, because, it widely used
in computers and microprocessor-based
system .
AdditionAddition
0 0 0 0 0 1 1 1
+0 0 0 0 0 1 0 0
0 0 0 0 1 0 1 1
0 0 0 0 1 1 1 1
+1 1 1 1 1 0 1 0
0 0 0 0 1 0 0 1 1
Discard
Carry
7 + 4
15 + (-6)
The Sum is Positive and is therefore in true binary
The Final Carry is Discarded.
The Sum is Positive and is therefore in true binary
AdditionAddition
0 0 0 1 0 0 0 0
+1 1 1 0 1 0 0 0
1 1 1 1 1 0 0 0
16 + (-24)
The Sum is Negative and is therefore in
2’s complement form
1 1 1 1 1 0 1 1
+ 1 1 1 1 0 1 1 1
1 1 1 1 0 0 1 0
-5 + (-9)
1
Discard
Carry
The Final Carry is Discarded.
The Sum is Negative and is therefore in
2’s complement form
SubtractionSubtraction
To subtract two signed numbers, take the 2’s
Complement of the subtrahend and ADD. Discard any
final carry bit
0 0 0 0 1 0 0 0 - 0 0 0 0 0 0 1 1
8 – 3 = 8 + (-3) = 5
0 0 0 0 1 0 0 0
1 1 1 1 1 1 0 1
0 0 0 0 0 1 0 1
+ 2’s Complement
1Discard Cary Difference
MultiplicationMultiplication
The numbers in a multiplication are the multiplicand, the
multiplier and the product. Direct Addition and Partial
Products are two basic methods for performing multiplication
using addition.
8 X 3 = 24
8 + 8 + 8 = 24
(Decimal)
0 0 0 0 1 0 0 0
0 0 0 0 1 0 0 0
0 0 0 1 0 0 0 0
0 0 0 0 1 0 0 0
0 0 0 1 1 0 0 0
+
+
Standard Procedure
DivisionDivision
The division operation in computers is accomplished using
subtraction. Since subtraction is done with an adder, division
can also be accomplished with an adder. The result of a
division is called the quotient.
Step 1:
Determine the SIGN BIT for both DIVIDEND and DIVISOR
Step 2:
Subtract the DIVISOR from the DIVIDEND using 2’s Complement addition to get
the first partial remainder and ADD 1 to quotient. If ZERO or NEGATIVE the
division is complete.
Step 3:
Subtract the divisor from the partial remainder and ADD 1 to the quotient. If the
result is POSITIVE repeat Step 2 or If ZERO or NEGATIVE the division is
complete.
Hexadecimal NumbersHexadecimal Numbers
Most digital systems deal with groups of bits in Most digital systems deal with groups of bits in
even powers of 2 such as 8, 16, 32, and 64 bits.even powers of 2 such as 8, 16, 32, and 64 bits.
Hexadecimal uses groups of 4 bits.Hexadecimal uses groups of 4 bits.
Base 16Base 16
16 possible symbols16 possible symbols
0-9 and A-F0-9 and A-F
Allows for convenient handling of long binary Allows for convenient handling of long binary
strings.strings.
Hexadecimal NumbersHexadecimal Numbers
Convert from hex to decimal by Convert from hex to decimal by
multiplying each hex digit by its multiplying each hex digit by its
positional weight.positional weight.
Example:Example:
)16(3)16(6)16(1163
012
16
131662561
10355
Hexadecimal NumbersHexadecimal Numbers
Convert from decimal to hex by using the Convert from decimal to hex by using the
repeated division method used for decimal to repeated division method used for decimal to
binary and decimal to octal conversion.binary and decimal to octal conversion.
Divide the decimal number by 16Divide the decimal number by 16
The first remainder is the LSB and the last is The first remainder is the LSB and the last is
the MSB.the MSB.
Note, when done on a calculator a decimal Note, when done on a calculator a decimal
remainder can be multiplied by 16 to get the result. remainder can be multiplied by 16 to get the result.
If the remainder is greater than 9, the letters A If the remainder is greater than 9, the letters A
through F are used.through F are used.
Example of hex to binary conversion:Example of hex to binary conversion:
Hexadecimal NumbersHexadecimal Numbers
Hexadecimal NumbersHexadecimal Numbers
Hexadecimal NumbersHexadecimal Numbers
Hexadecimal is useful for representing Hexadecimal is useful for representing
long strings of bits.long strings of bits.
Understanding the conversion process Understanding the conversion process
and memorizing the 4 bit patterns for each and memorizing the 4 bit patterns for each
hexadecimal digit will prove valuable later.hexadecimal digit will prove valuable later.
BCDBCD
Binary Coded Decimal (BCD) is another Binary Coded Decimal (BCD) is another
way to present decimal numbers in binary way to present decimal numbers in binary
form.form.
BCD is widely used and combines BCD is widely used and combines
features of both decimal and binary features of both decimal and binary
systems.systems.
Each digit is converted to a binary Each digit is converted to a binary
equivalent.equivalent.
BCDBCD
To convert the number 874To convert the number 874
1010 to BCD: to BCD:
88 77 44
1000 0111 0100 = 1000011101001000 0111 0100 = 100001110100
BCDBCD
Each decimal digit is represented using 4 bits.Each decimal digit is represented using 4 bits.
Each 4-bit group can never be Each 4-bit group can never be greater than 9greater than 9..
Reverse the process to convert BCD to Reverse the process to convert BCD to
decimal.decimal.
BCDBCD
BCD is not a number system.BCD is not a number system.
BCD is a decimal number with each digit BCD is a decimal number with each digit
encoded to its binary equivalent.encoded to its binary equivalent.
A BCD number is not the same as a A BCD number is not the same as a
straight binary number.straight binary number.
The primary advantage of BCD is the The primary advantage of BCD is the
relative ease of converting to and from relative ease of converting to and from
decimal.decimal.
Alphanumeric CodesAlphanumeric Codes
Represents characters and functions found on a Represents characters and functions found on a
computer keyboard.computer keyboard.
ASCII – American Standard Code for ASCII – American Standard Code for
Information Interchange.Information Interchange.
Seven bit code: 2Seven bit code: 2
77
= 128 possible code groups = 128 possible code groups
Table 2-4 lists the standard ASCII codesTable 2-4 lists the standard ASCII codes
Examples of use are: to transfer information between Examples of use are: to transfer information between
computers, between computers and printers, and for computers, between computers and printers, and for
internal storage.internal storage.