Industrial - Lecture 2 - Number Systems

Download as pdf or txt
Download as pdf or txt
You are on page 1of 72

INDUSTRIAL ELECTRONICS

LECTURE 2:

NUMBER SYSTEMS
CONTENT

 Decimal Numbers
 Binary Numbers
 Decimal-to-Binary Conversion
 Binary Arithmetic
 Complements of Binary Numbers
 Hexadecimal Numbers
 Octal Numbers
 Binary Coded Decimal (BCD)
 References
INTRODUCTION
 The binary number system and digital codes are
fundamental to computers and to digital electronics
in general.

 In this presentation, we’ll discuss the binary


number system and its relationship to other
number systems such as decimal, hexadecimal, and
octal.

 Arithmetic operations with binary numbers are also


covered.
DECIMAL NUMBERS
 In decimal number system each of the ten digits, 0
through 9, represents a certain value of quantity.

 If there is a need to express a quantity greater than


nine, then two or more digits can be used, and the
position of each digit within the number indicates
the magnitude it represents.

 The position of each digit in a decimal number


indicates the magnitude of the quantity represented
and can be assigned a weight.
Example of Decimal Number
Weight of Decimal Numbers
 The weights for whole numbers are positive powers
of ten that increase from right to left, beginning
with 100 = 1.

 For fractional numbers, the weights are negative


powers of ten that decrease from left to right
beginning with 10-1.

 The value of a decimal number is the sum of the


digits after each digit has been multiplied by its
weight
Example 01
 Express the decimal number 47 as a sum of the
values of each digit.

Question 01
 Determine the value of each digit in 939.
Example 02
 Express the decimal number 568.23 as a sum of the
values of each digit.

Question 02
 Determine the value of each digit in 67.924
BINARY NUMBERS
 The binary number system is another way to
represent quantities.
 It has only two digits (bits), 1 and 0

 The decimal system with its ten digits is a base-ten


system; the binary system with its two digits is a
base-two system
 The position of a 1 or 0 in a binary number
indicates its weight, or value within the number,
just as the position of a decimal digit determines
the value of that digit.
 The weights in a binary number are based on
powers of two.
Counting in Binary
 Begin counting: 0, 1

 Include another
digit position and
continue: 10, 11

 With three digit


positions you can
continue to count:
100, 101, 110, and
111.
Counting in Binary
 From the previous table: four bits are can only
count from 0 to 15

 In general, with n bits you can count up to a


number equal to 2n - 1
 Largest decimal number = 2n – 1

 For example, with five bits (n = 5) you can count


from zero to thirty-one.
25 - 1 = 32 - 1 = 31
Application
 Example of counting tennis balls going into a box
from a conveyor belt assuming that nine balls are to
go into each box.
The Weighting Structure of Binary
Numbers
 The right-most bit is the LSB (least significant bit)
in a binary whole number and has a weight of 20 =
1.
 The weights increase from right to left by a power
of two for each bit.
 The left-most bit is the MSB (most significant bit);
its weight depends on the size of the binary
number.
 The fractional weights decrease from left to right by
a negative power of two for each bit.
where n is the
number of bits from
the binary point
Example of Binary Weights
 The weight doubles for each positive power of two
and the weight is halved for each negative power of
two.
BINARY-to-DECIMAL CONVERSION
 The decimal value of any binary number can be found
by adding the weights of all bits that are 1 and
discarding the weights of all bits that are 0.
Example 03
 Convert the binary whole number 1101101 to decimal.

Question 03
 Convert the binary number 10010001 to decimal.
Example 04
 Convert the fractional binary number 0.1011 to
decimal.

 Question 04
 Convert the binary number 10.111 to decimal.
CHECKUP QUESTIONS
1. What is the largest decimal number that can be
represented in binary with eight bits?
2. Determine the weight of the 1 in the binary
number 10000.
3. Convert the binary number 10111101.011 to
decimal
DECIMAL-to-BINARY CONVERSION
 Three main methods can be used for conversion
1. The sum-of-weights method

2. The repeated division-by-2 method

3. The repeated multiplication-by-2


method
Sum-of-Weights Method
 To get the binary number for a given decimal
number, find the binary weights that add up to the
decimal number.

 An easy way to remember binary weights is that


the lowest is 1, which is 20, and by doubling any
weight, you get the next higher weight.

 A list of seven binary weights would be 64, 32, 16, 8,


4, 2, 1
Illustration
 Example 9 can be expressed as the sum of binary
weights as
9 = 8 + 1 or 9 = 23 + 20

 Placing 1s in the appropriate weight positions, 23


and 20, and 0s in the 22 and 21 positions determines
the binary number for decimal 9.
Example 05
 Convert the following decimal numbers to binary:
(a) 12 (b) 25 (c) 58 (d) 82

 Question
 Convert the decimal number 125 to binary
Repeated Division-by-2 Method
 To get the binary number for a given decimal
number, divide the decimal number by 2 until the
quotient is 0. Remainders form the binary number

 The first remainder to be produced is the LSB (least


significant bit) in the binary number, and the last
remainder to be produced is the MSB (most
significant bit).
Illustration
 Converting the decimal number 12 to binary
Example 06
 Convert the following decimal numbers to binary:
(a) 19 (b) 45

 Question
 Convert decimal number 39 to binary
Repeated Multiplication by 2
 Decimal fractions can be converted to binary by
repeated multiplication by 2
 For example, to convert the decimal fraction
0.3125 to binary, begin by multiplying 0.3125 by
2 and then multiplying each resulting fractional
part of the product by 2 until the fractional
product is zero or until the desired number of
decimal places is reached
 The carry digits, or carries, generated by the
multiplications produce the binary number.
 The first carry produced is the MSB, and the last
carry is the LSB.
Illustration
Converting Decimal Fractions to Binary
 Sum-of-Weights Method can be applied to
fractional decimal numbers, as shown in the
following example:

0.625 = 0.5 + 0.125 = 2−1 + 2−3 = 0.101

 There is a 1 in the 2−1 position, a 0 in the 2−2


position, and a 1 in the 2−3 position
CHECKUP QUESTIONS
1. Convert each decimal number to binary by using
the sum-of-weights method:
(a) 23 (b) 57 (c) 45.5

2. Convert each decimal number to binary by using


the repeated division-by-2 method (repeated
multiplication-by-2 for fractions):
(a) 14 (b) 21 (c) 0.375
BINARY ARITHMETIC
 To understand digital systems, you must know the
basics of
1. Binary addition
2. Binary subtraction
3. Binary multiplication, and
4. Binary division
Binary Addition
 Four rules for adding binary digits (bits)
0 + 0 = 0 Sum of 0 with a carry of 0
0 + 1 = 1 Sum of 1 with a carry of 0
1 + 0 = 1 Sum of 1 with a carry of 0
1 + 1 = 10 Sum of 0 with a carry of 1
 The last condition creates a sum of 0 in a given
column and a carry of 1 over to the next column
to the left
 Example addition of 11 + 1
Adding 1s with a Carry of 1
 When there is a carry of 1, then you have a
situation in which three bits being added (a bit in
each of the two numbers and a carry bit).
Example 07
 Add the following binary numbers:
(a) 11 + 11 (b) 100 + 10
(c) 111 + 11 (d) 110 + 100

 Question: Add 1111 and 1100


Binary Subtraction
 Four basic rules of subtracting bits
0-0=0
1-1=0
1-0=1
0 - 1 = 10 - 1 with a borrow of 1
 A borrow is required in binary only when you try
to subtract a 1 from a 0.
 In this case, when a 1 is borrowed from the next
column to the left, a 10 is created in the column
being subtracted, and the last of the four basic rules
just listed must be applied.
Example 08
 Perform the following binary subtractions:
(a) 11 - 01 (b) 11 - 10

 Question: Subtract 100 from 111.


Example 09
 Subtract 011 from 101

 Question: Subtract 101 from 110.


Binary Multiplication
 Four basic rules of multiplying bits
0*0=0
0*1=0
1*0=0
1*1=1
 Multiplication is performed with binary numbers
in the same manner as with decimal numbers.

 It involves forming partial products, shifting


each successive partial product left one place,
and then adding all the partial products
Example 10
 Perform the following binary multiplications:
(a) 11 * 11 (b) 101 * 111

 Question: Multiply 1101 * 1010


Binary Division
 Division in binary follows the same procedure as
division in decimal
 Example 11: Perform the following binary
divisions: (a) 110 ÷ 11 (b) 110 ÷ 10

 Question: Divide 1100 by 100.


CHECKUP QUESTIONS
1. Perform the following binary additions:
(a) 1101 + 1010 (b) 10111 + 01101

2. Perform the following binary subtractions:


(a) 1101 - 0100 (b) 1001 - 0111

3. Perform the indicated binary operations:


(a) 110 * 111 (b) 1100 ÷ 011
COMPLEMENTS OF BINARY NUMBERS
 The 1’s complement and the 2’s complement of a
binary number are important because they
permit the representation of negative numbers.

 The method of 2’s complement arithmetic is


commonly used in computers to handle negative
numbers.
Finding 1’s Complement
 The 1’s complement of a binary number is found
by changing all 1s to 0s and all 0s to 1s, as
illustrated

 The simplest way to obtain the 1’s complement of


a binary number with a digital circuit is to use
parallel inverters (NOT circuits)
Finding 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
 Example 12: Find the 2’s complement of 10110010.

 Question: Determine the 2’s complement of 11001011


Alternative for Finding 2’s Complement
1.Start at the right with the LSB and write the bits
as they are up to and including the first 1.
2. Take the 1’s complements of the remaining bits

 Example 13: Find the 2’s complement of


10111000 using the alternative method.
Realizing the 2’s Complement
 The 2’s complement of a negative binary number
can be realized using inverters and an adder
CHECKUP QUESTIONS
1. Determine the 1’s complement of each binary
number:
(a) 00011010 (b) 11110111 (c) 10001101

2. Determine the 2’s complement of each binary


number:
(a) 00010110 (b) 11111100 (c) 10010001
SIGNED 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 left-most bit in a signed binary number is
the sign bit, which tells you whether the number
is positive or negative.
 A 0 sign bit indicates a positive number, and a 1
sign bit indicates a negative number.
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
 For example, the decimal number +25 is
expressed as an 8-bit signed binary number using
the sign-magnitude form as:

 The decimal number -25 is expressed as


10011001
 In the sign-magnitude form, a negative number has
the same magnitude bits as the corresponding
positive number but the sign bit is a 1 rather than a
zero.
Complement of Signed Numbers
 In the 1’s complement form, a negative number is
the 1’s complement of the corresponding positive
number.
 For example, using eight bits, 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.
 Using eight bits, decimal number -25 expressed
as the 2’s complement of +25 (00011001).
Inverting each bit and adding 1, you get -25 =
11100111
Hexadecimal Numbers
 The hexadecimal number system has sixteen
characters;

 It is primary used as a compact way of displaying


or writing binary numbers because it is very easy
to convert between binary and hexadecimal.

 Hexadecimal is widely used in computer and


microprocessor applications.

 The hexadecimal number system has a base of


sixteen; that is, it is composed of 16 numeric and
alphabetic characters.
Hexadecimal Numbers
 Most digital systems
process binary data in
groups that are multiples
of four bits, making the
hexadecimal number very
convenient because each
hexadecimal digit
represents a 4-bit binary
number

 Subscript 16, or sometimes letter h may be used


to designate hexadecimal numbers.
Counting in Hexadecimal
 Simply start over with another column and
continue as follows:

 With two hexadecimal digits, you can count up to


FF16 , which is decimal 255.

 To count beyond this, three hexadecimal digits


are needed. For instance, 10016 is decimal 256,
10116 is decimal 257, and so forth.
Binary-to-Hexadecimal Conversion
 Converting a binary number to hexadecimal is a
straightforward procedure.

 Simply break the binary number into 4-bit


groups, starting at the right-most bit and replace
each 4-bit group with the equivalent hexadecimal
symbol.
Example 14
 Convert the following binary numbers to
hexadecimal:
(a) 1100101001010111 (b) 111111000101101001
Hexadecimal-to-Binary Conversion
 To convert from a hexadecimal number to a
binary number, reverse the previous process and
replace each hexadecimal symbol with the
appropriate four bits.
 Example 15: Determine the binary numbers for
the following hexadecimal numbers:
(a) 10A416 (b) CF8E16 (c) 974216
Hexadecimal-to-Decimal Conversion
 One way to find the decimal equivalent of a
hexadecimal number is to first convert the
hexadecimal number to binary and then convert
from binary to decimal.
 Example 16: Convert the following hexadecimal
numbers to decimal: (a) 1C16 (b) A8516
Hexadecimal-to-Decimal Conversion
 Another way to convert a hexadecimal number to
its decimal equivalent is to multiply the decimal
value of each hexadecimal digit by its weight and
then take the sum of these products.
 The weights of a hexadecimal number are
increasing powers of 16 (from right to left).
 For a 4-digit hexadecimal number, the weights
are;
Example 17
 Convert the following hexadecimal numbers to
decimal: (a) E516 (b) B2F816

Solution
Octal Numbers
 The octal number system is composed of eight
digits, which are; 0, 1, 2, 3, 4, 5, 6, 7

 To count above 7, begin another column and start


over: 10, 11, 12, 13, 14, 15, 16, 17, 20, 21, …

 Counting in octal is similar to counting in decimal,


except that the digits 8 and 9 are not used.

 Subscript 8 is used to distinguish octal numbers,


e.g. 158
Octal-to-Decimal Conversion
 Octal numbers being base of eight, each successive
digit position is an increasing power of eight,
beginning in the right-most column with 80.
 Example 18: Converting 23748 to decimal

Solution
Decimal-to-Octal Conversion
 A method of converting a decimal number to an
octal number is the repeated divisionby-8 method
 Example 19: Converting Decimal 359 to octal
Octal-to-Binary Conversion
 Each octal digit is represented by three bits as
shown in the table hereafter.

 To convert an octal number to a binary number,


simply replace each octal digit with the
appropriate three bits.
Example 20
 Convert each of the following octal numbers to
binary:
(a) 138 (b) 258 (c) 1408 (d) 75268
Binary-to-Octal Conversion
 Conversion of a binary number to an octal
number is the reverse of the octal-to-binary
conversion
 Start with the right-most group of three bits and,
moving from right to left, convert each 3-bit
group to the equivalent octal digit.
 If there are not three bits available for the left-
most group, add either one or two zeros to make a
complete group.
Example 21
Convert each of the following binary numbers to
octal:
(a) 110101 (b)101111001
(c)100110011010 (d)11010000100
Binary Coded Decimal (BCD)
 Binary coded decimal (BCD) is a way to express
each of the decimal digits with a binary code.
 There are only ten code groups in the BCD
system, so it is very easy to convert between
decimal and BCD.
 Because we like to read and write in decimal, the
BCD code provides an excellent interface to
binary systems.
 Examples of such interfaces are keypad inputs
and digital readouts.
The 8421 BCD Code
 The 8421 code is a type of BCD (binary coded
decimal) code.
 Binary coded decimal means that each decimal
digit, 0 through 9, is represented by a binary code
of four bits.
 The 8421 code is the predominant BCD code, and
when we refer to BCD, we always mean the 8421
code unless otherwise stated.
Invalid Codes
 You should realize that, with four bits, sixteen
numbers (0000 through 1111) can be represented
but that, in the 8421 code, only ten of these are
used.
 The six code combinations that are not used—
1010, 1011, 1100, 1101, 1110, and 1111—are
invalid in the 8421 BCD code
 To express any decimal number in BCD, simply
replace each decimal digit with the appropriate 4-
bit code
Example 22
 Convert each of the following decimal numbers to
BCD:
(a) 35 (b) 98
(c) 170 (d) 2469
Example 23
 Convert each of the following BCD codes to
decimal:
(a)10000110
(b)001101010001
(c)1001010001110000
Reading Task
 From the given reference books, study about
Digital Codes, focus on:
1.Gray Code
2.ASCII Code
References
1. Thomas L. Floyd. (2008). “Digital
Fundamentals” (10th Edition). New Jersey: NJ.
Pearson education. – Chapter 2

2. William Kleitz. (2012). “Digital Electronics: A


Practical Approach with VHDL”, (8th Edition).
New Jersey: NJ. Pearson education.–Chapter 1

3. Roger L. Tokheim. (2007). “Digital Electronics:


Principles and Applications”, Pearson education
– Chapter 2
Thank You
&

You might also like