Sie sind auf Seite 1von 54

# CHAPTER 2: NUMBER

## SYSTEMS & CODES

•2.1 - Number Systems: Decimal, Binary,
Octal & Hexadecimal
•2.2 - Numbering Conversions
•2.3 - Binary Arithmetic
•2.4 - Code Numbers: BCD Code, ASCII
Code, Gray Code
•2.5 - Representing Number Systems: Sign &
Magnitude, 1’s & 2’s Complement
BEKU 1413 (DIGITAL ELECTRONICS & 1
SYSTEMS): CHAPTER 2
Introduction
Number systems and digital codes are fundamental
to computers and digital electronics.

## In this chapter, we will see the relationships

between binary number system with other number
systems such as decimal, hexadecimal, and octal.

## Arithmetic operations with binary numbers are

covered to provide a basis for understanding how
computers and many other types of digital system
work.

## Digital codes such as binary coded decimal (BCD),

the GRAY code, and the ASCII are covered.
BEKU 1413 (DIGITAL ELECTRONICS & 2
SYSTEMS): CHAPTER 2
2.1 - Number Systems: Decimal, Binary,
Octal & Hexadecimal
 Decimal Numbers
 Is the most familiar number system that
people use in every day life.
 It uses 10 different symbols to express any
number. Those are: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
and called as digits of a number.
 It is also referred as Base 10 number system
or Radix of 10 number system.
 Each digit will give different value. If to
present a value more than 9 then you should
have more than one digit.
BEKU 1413 (DIGITAL ELECTRONICS & 3
SYSTEMS): CHAPTER 2
BEKU 1413 (DIGITAL ELECTRONICS & 4
SYSTEMS): CHAPTER 2
 Binary Numbers
 Useful in electronics because it uses only two
digits, 1 and 0.
 Each place in binary number is called a bit.
Eg: 10110 is a 5-bit binary number.
 The first place on the right is called the least
significant bit (LSB) and the left-most place
is called the most-significant bit (MSB).

## BEKU 1413 (DIGITAL ELECTRONICS & 5

SYSTEMS): CHAPTER 2
 The weights for the binary system are found
by – raising the base value, 2, by a power
equal to the value of the position of a digit in a
binary number.
 Those weights, starting with the LSB, are

## BEKU 1413 (DIGITAL ELECTRONICS & 6

SYSTEMS): CHAPTER 2
 For N bits, we can count 2N different decimal
numbers ranging from 0 to 2N-1.
 In general, with N bits we can count up
2N-1 for a total of 2N.

## BEKU 1413 (DIGITAL ELECTRONICS & 7

SYSTEMS): CHAPTER 2
BEKU 1413 (DIGITAL ELECTRONICS & 8
SYSTEMS): CHAPTER 2
 Octal Numbers
 There are eight different digits to work with,
zero through seven (0 – 7)
 Often used in digital computer work.
 Base of 8.
 The digit positions in an octal number have
weights as follows:

## BEKU 1413 (DIGITAL ELECTRONICS & 9

SYSTEMS): CHAPTER 2
BEKU 1413 (DIGITAL ELECTRONICS & 10
SYSTEMS): CHAPTER 2
 Hexadecimal Number System (base-16)
 Uses group of 4 bits.
 16 possible symbols: 0 – 9 and A – F.
 Allows for convenient handling of long binary
strings.

## BEKU 1413 (DIGITAL ELECTRONICS & 11

SYSTEMS): CHAPTER 2
2.2 - Numbering Conversions
 Binary to Decimal Conversion
 Convert binary to decimal by summing
together the weights of the various positions
in the binary number that contain a 1.
 For the fractional Binary Numbers, weights for
binary number decimal numbers are derived
by raising the base 2 by negative components.

## BEKU 1413 (DIGITAL ELECTRONICS & 12

SYSTEMS): CHAPTER 2
BEKU 1413 (DIGITAL ELECTRONICS & 13
SYSTEMS): CHAPTER 2
 Decimal to Binary Conversion
 Two methods to convert Decimal to Binary:
 Reverse process described at (Binary to Decimal
Conversion).
 Use repeated division.
 Repeated Division:
 Divide the decimal number by 2.
 Write the remainder after each division until a
quotient of zero is obtained.
 The first remainder is LSB and the last is MSB.

## BEKU 1413 (DIGITAL ELECTRONICS & 14

SYSTEMS): CHAPTER 2
Example 2-4:
1. Convert 29110 to a binary number.

Solution
291 / 2 = 145 remainder 1 LSB
145 / 2 = 72 remainder 1
72 / 2 = 36 remainder 0
36 / 2 = 18 remainder 0
18 / 2 = 9 remainder 0
9 /2 = 4 remainder 1
4/2 =2 remainder 0
2/2 =1 remainder 0
1/2 =0 remainder 1 MSB

29110 = 1001000112

## BEKU 1413 (DIGITAL ELECTRONICS & 15

SYSTEMS): CHAPTER 2
2. Convert 102410 to a binary number.

Solution
1024 / 2 = 512 remainder 0 LSB
512 / 2 = 256 remainder 0
256 / 2 = 128 remainder 0
128 / 2 = 64 remainder 0
64 / 2 = 32 remainder 0
32 / 2 = 16 remainder 0
16 / 2 =8 remainder 0
8/2 =4 remainder 0
4/2 =2 remainder 0
2/2 =1 remainder 0
1/2 =0 remainder 1 MSB
102410 = 100000000002

## BEKU 1413 (DIGITAL ELECTRONICS & 16

SYSTEMS): CHAPTER 2
 Fractional Radix Conversion:
Example 2-5:
1. Convert 0.7510 to binary.

Solution
Integers
Multiply 0.75 by 2 (0.75)2 = 1.5  1 (MSB)
Multiply 0.5 by 2 (0.5)2 = 1.0  1
Multiply 0 by 2 (0)2 = 0.0  0 (LSB)
Checking the result, we find
0.7510 = (1)2-1 + (1)2-2 = ½ + ¼ = ¾

## BEKU 1413 (DIGITAL ELECTRONICS & 17

SYSTEMS): CHAPTER 2
2. Convert 95.062510 to binary.

Solution
The conversion is accomplished in two parts.

## First, convert the integer part of the decimal number by successive

division.
95/2 = 47 remainder 1 LSB
47/2 = 23 remainder 1
23/2 = 11 remainder 1
11/2 =5 remainder 1
5/2 =2 remainder 1
2/2 =1 remainder 0
½ =0 remainder 1 MSB
9510 = 10111112

## BEKU 1413 (DIGITAL ELECTRONICS & 18

SYSTEMS): CHAPTER 2
Second, convert the fraction.

## (0.0625)2 = 0.125  0 MSB

(0.125)2 = 0.25  0
(0.25)2 = 0.5  0
(0.5)2 = 1.0  1 LSB
0.062510 = 00012

 95.062510 = 1011111.00012

## BEKU 1413 (DIGITAL ELECTRONICS & 19

SYSTEMS): CHAPTER 2
 Octal to Decimal Conversion
 An octal number can be converted to its
decimal equivalent by multiplying each octal
digit by its positional weight.

## BEKU 1413 (DIGITAL ELECTRONICS & 20

SYSTEMS): CHAPTER 2
 Decimal to Octal Conversion
 A decimal integer can be converted to octal by
using the same repeated-division method that
used in the decimal to binary conversion.
 But with a division factor of 8 instead of 2.

## BEKU 1413 (DIGITAL ELECTRONICS & 21

SYSTEMS): CHAPTER 2
 Octal to Binary Conversion
 To convert an octal to binary number, simply
replace each octal digit with the appropriate
three bits.

## BEKU 1413 (DIGITAL ELECTRONICS & 22

SYSTEMS): CHAPTER 2
 Binary to Octal Conversion
 Conversion of a binary number to an octal
number is the reverse of the octal-to-binary
conversion.

## BEKU 1413 (DIGITAL ELECTRONICS & 23

SYSTEMS): CHAPTER 2
 Hexadecimal to Decimal Conversion
 Each hexadecimal digit position has a weight
that is a power of 16.
 The LSD has a weight of 160=1

## BEKU 1413 (DIGITAL ELECTRONICS & 24

SYSTEMS): CHAPTER 2
 Decimal to Hexadecimal Conversion

## BEKU 1413 (DIGITAL ELECTRONICS & 25

SYSTEMS): CHAPTER 2
2.3 - Binary Arithmetic
 Binary Addition
 The rules for binary numbers are given in
table below.

## BEKU 1413 (DIGITAL ELECTRONICS & 26

SYSTEMS): CHAPTER 2
 Binary Subtraction

## BEKU 1413 (DIGITAL ELECTRONICS & 27

SYSTEMS): CHAPTER 2
 Binary Multiplication
0X0=0
0X1=0
1X0=0 100110
1X1=1 X101
100110
000000
100110
10111110
BEKU 1413 (DIGITAL ELECTRONICS & 28
SYSTEMS): CHAPTER 2
 Binary Division

## BEKU 1413 (DIGITAL ELECTRONICS & 29

SYSTEMS): CHAPTER 2
2.4 - Code Numbers: BCD Code, ASCII
Code, Gray Code
 BCD Code
 Binary Coded Decimal (BCD) is another way to
present decimal numbers in binary form.
 BCD is widely used and combines features of
both decimal and binary systems.
 Each digit is converted to a binary equivalent.
 Look at the below example:

## BEKU 1413 (DIGITAL ELECTRONICS & 30

SYSTEMS): CHAPTER 2
 Each digit always uses four bits and not a
number system.
 The BCD value can never be greater than 9 (its
called 8421 code too  23, 22, 21, 20 )
 BCD is decimal number with each digit
encoded to its binary equivalent.
 A BCD number is not the same as a straight
binary number.
 The primary advantage of BCD is the relative
ease of converting to and from decimal.

## BEKU 1413 (DIGITAL ELECTRONICS & 31

SYSTEMS): CHAPTER 2
BEKU 1413 (DIGITAL ELECTRONICS & 32
SYSTEMS): CHAPTER 2
 BCD Addition:
 Here are the steps to add BCD numbers:
 Step 1: Add the two BCD numbers. (Using the rules
for binary arithmetic)
 Step 2: If a 4-bit sum equal to / less than 9, it is a
valid BCD number.
 Step 3: If a 4-bit sum is greater than 9 / if a carry
out of the 4-bit group is generated, it is invalid result.

Valid result

## BEKU 1413 (DIGITAL ELECTRONICS & 33

SYSTEMS): CHAPTER 2
 Alphanumeric Codes
 Represents characters and functions found on
a computer keyboard.
 ASCII – American Standard Code for
information Interchange.
 Seven bit code, 27 or 128 possible code groups
 Table 2-1 lists some of the ASCII code
 Examples of use are: to transfer information between
computers, between computers and printers, and for
internal storage.

## BEKU 1413 (DIGITAL ELECTRONICS & 34

SYSTEMS): CHAPTER 2
BEKU 1413 (DIGITAL ELECTRONICS & 35
SYSTEMS): CHAPTER 2
BEKU 1413 (DIGITAL ELECTRONICS & 36
SYSTEMS): CHAPTER 2
 The Gray Code
 Unweighted and is not an arithmetic code.
 No specific weights assigned to the bit
positions.
 It exhibits only a single bit change from one
code word to the next in sequence.
 The Gray code can have any number of bits.

## BEKU 1413 (DIGITAL ELECTRONICS & 37

SYSTEMS): CHAPTER 2
 Binary to GRAY code conversion
 MSB in the Gray Code is the same as in the binary
 Going from left to right, add each adjacent pair of
binary code bits to get the next Gray code bit.
Discard carries.

## BEKU 1413 (DIGITAL ELECTRONICS & 38

SYSTEMS): CHAPTER 2
 GRAY code to Binary conversion
 MSB in the Gray Code is the same as in the binary
 Going from left to right, add each binary code bit
generated to the Gray code bit in the next adjacent
position. Discard carries.

## BEKU 1413 (DIGITAL ELECTRONICS & 39

SYSTEMS): CHAPTER 2
2.5 - Representing Number Systems: Sign &
Magnitude, 1’s & 2’s Complement
 Signed Number
 A signed number consists of both sign and
magnitude information.
 The sign indicates the number is positive /
negative.
 The magnitude is the value of the number.
 The magnitude bits are the true binary
equivalent of the decimal value being
represented.
 The most commonly used system for
representing signed binary number is the 2’s
complement system.
BEKU 1413 (DIGITAL ELECTRONICS & 40
SYSTEMS): CHAPTER 2
 The Sign Bit
 The left most bit in a signed binary number is the
sign bit, which will indicate the number is positive /
negative.
 The remaining bits are the magnitude bits.

## BEKU 1413 (DIGITAL ELECTRONICS & 41

SYSTEMS): CHAPTER 2
 1’s Complement Form
 The 1’s complement of a binary number is
obtained by changing each 0 to a 1 and each 1
to a 0.
 The process is shown below:

## BEKU 1413 (DIGITAL ELECTRONICS & 42

SYSTEMS): CHAPTER 2
 2’s Complement Form
 The 2’s complement of binary number is
formed by taking the 1’s complement of the
number and adding 1 to the LSB position.

## BEKU 1413 (DIGITAL ELECTRONICS & 43

SYSTEMS): CHAPTER 2
 Alternative method
 Change all bits to the left of the least significant 1 to
get 2’s complement.

## BEKU 1413 (DIGITAL ELECTRONICS & 44

SYSTEMS): CHAPTER 2
 Representing Signed Numbers Using 2’s
complement

##  If the number is positive, the magnitude is

represented in its true binary form, and a sign
bit of 0 is placed in front of the MSB.

## BEKU 1413 (DIGITAL ELECTRONICS & 45

SYSTEMS): CHAPTER 2
 If the number is negative, the magnitude is
represented in its 2’s complement form, and a
sign bit of 1 is placed in front of the MSB.

## BEKU 1413 (DIGITAL ELECTRONICS & 46

SYSTEMS): CHAPTER 2
 2’s complement allows us to perform the
operation of subtraction by actually performing
addition.

## BEKU 1413 (DIGITAL ELECTRONICS & 47

SYSTEMS): CHAPTER 2
 Negation
 Is the operation of converting a positive number to
its negative equivalent / a negative number to its
equivalent.

## BEKU 1413 (DIGITAL ELECTRONICS & 48

SYSTEMS): CHAPTER 2
 Special Case in 2’s Complement representation

## BEKU 1413 (DIGITAL ELECTRONICS & 49

SYSTEMS): CHAPTER 2
 Addition In the 2’s complement System
 Case 1: Two Positive Numbers
 The addition of two positive numbers is straight
forward.

## BEKU 1413 (DIGITAL ELECTRONICS & 50

SYSTEMS): CHAPTER 2
 Case 2: Positive Number and Smaller Negative
Number

## BEKU 1413 (DIGITAL ELECTRONICS & 51

SYSTEMS): CHAPTER 2
 Case 3: Positive Number and Larger Negative
Number

## BEKU 1413 (DIGITAL ELECTRONICS & 52

SYSTEMS): CHAPTER 2
 Case 4: Negative Numbers Two

## BEKU 1413 (DIGITAL ELECTRONICS & 53

SYSTEMS): CHAPTER 2
THE END

## BEKU 1413 (DIGITAL ELECTRONICS & 54

SYSTEMS): CHAPTER 2