0% found this document useful (0 votes)
21 views

Chapter2 Numbering Systems and Conversions

Uploaded by

fjburgosf
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views

Chapter2 Numbering Systems and Conversions

Uploaded by

fjburgosf
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 67

Chapter 2.

Number systems, operations and


conversions

Francisco Javier Burgos Flórez

Mechatronics Engineering department

1
Introduction
• The binary number system and its relationship to other number systems such as decimal,
hexadecimal, and octal are presented.

• Arithmetic operations with binary numbers are covered to provide a basis for
understanding how computers and many other types of digital systems work.

• Digital codes such as binary coded decimal (BCD), and the ASCII are covered as well as
the parity method for detecting errors in codes.

2
The decimal system

3
Example 1
• Express the decimal number 47 as a sum of the values of each digit

4
Example 2
• Express the decimal number 568.23 as a sum of the values of each digit

5
Binary numbers: Another way to represent
quantities
Four bits are required to count from zero to 15.

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


number equal to 2𝑛 − 1, thus,

Largest decimal number = 2𝑛 − 1

With five bits (n = 5) you can count from zero to


thirty-one

25 − 1 = 31

With n=6

26 − 1 = 63
6
An application

Nine balls per box

7
The weighting structure of binary numbers

MSB LSB MSB LSB

MSB= Most significant bit


LSB= Least significant bit

8
Binary to decimal conversion. Exercise 1
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.

Convert the binary number 10111101.011 to decimal:

1. Determine the weight of each bit that is a 1 and then sum the weights to get the decimal number.

9
Binary to decimal conversion. Exercise 1
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.

Convert the binary number 10111101.011 to decimal:

1. Determine the weight of each bit that is a 1 and then sum the weights to get the decimal number.

Weight 27 26 25 24 23 22 21 20 . 2−1 2−2 2−3


Binary number 1 0 1 1 1 1 0 1 .0 1 1
10111101.011 = 27 + 25 + 24 + 23 + 22 + 20 + 2−2 + 2−3
10111101.011 = 128 + 32 + 16 + 8 + 4 + 1 + 0.25 + 0.125 = 189.375

10
Decimal to binary conversion with repeated
division by two
Convert the following decimal numbers to binary: 19

11
Decimal to binary conversion with repeated
division by two. Exercise 2
Convert the following decimal numbers to binary: 45

12
Decimal to binary conversion with repeated
division by two. Exercise 2
Convert the following decimal numbers to binary: 45

13
Decimal fraction to binary conversion with
repeated multiplication by two
Convert the following decimal fraction to binary: 0.3125

Carry is 1 since
multiplication was higher
or equal to 1! (i.e. 1.25)

14
Decimal fraction to binary conversion with
repeated multiplication by two. Exercise 3
Convert the following decimal fraction to binary: 0.5146

RTA = 0.10000011

15
Binary arithmetic: 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 of 0
1 + 0 = 1 Sum of 1 with a carry of 0
1 + 1 = 10 Sum of 0 with a carry of 1

16
Binary arithmetic: Addition

17
Binary arithmetic: Addition example
Add the following binary numbers: a) 11 + 11 , b) 100 + 10, c) 111 + 11, d) 110 + 100

18
Binary arithmetic: Subtraction
The four basic rules for subtracting binary digits (bits) are as follows:
0-0=0
1-1=0
1-0=1
10 - 1 = 1 (0 - 1 with a borrow of 1)

19
Binary arithmetic: Subtraction example
Perform the following binary subtraction: a) 101 - 011

20
Binary arithmetic: Multiplication
The four basic rules for multiplying bits are as follows:
0x0=0
0x1=0
1x0=0
1x1=1
Perform the following binary multiplications: (a) 11 x 11 and b) 101 x 111

21
Binary arithmetic: Division
Division in binary follows the same procedure as division in decimal.
Perform the following binary divisions: a) 110 / 11, b) 110 x 10

22
Exercise 4
Perform the following binary operations:
(a) 10111 + 01101
(b) 1001 – 0111
(c) 110 x 111
(d) 1100 / 011

23
Exercise 4
Perform the following binary operations:
(a) 10111 + 01101 = 100100
(b) 1001 – 0111 = 0010
(c) 110 x 111 = 101010
(d) 1100 / 011 = 100

24
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.

25
Finding 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,
as illustrated below:

26
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.
Find the 2’s complement of 10110010.

27
Finding the 2’s complement

The 2’s complement of a negative binary number can be realized using


inverters and an adder
28
Finding the 2’s complement. Exercise 5
Find the 2’s complement of 11001011.

29
Finding the 2’s complement. Exercise 5
Find the 2’s complement of 11001011.

00110101

Revert back to the original number by finding the 2’s complement of 00110101

30
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 sign indicates whether a number is positive or negative, and the magnitude is the
value of the number.

There are three forms in which signed integer (whole) numbers can be represented in
binary: sign-magnitude, 1’s complement, and 2’s complement.
Of these, the 2’s complement is the most important and the sign-magnitude is the
least used.

Here we will use the 2’s complement.

31
The sign bit and magnitude bits
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. The remaining bits are the magnitude bits.
For example, the decimal number +25 is expressed as an 8-bit signed binary number:

Negative numbers are the 2’s complements of the corresponding positive numbers.
Hence, Inverting each bit and adding 1, you get -25 as: 11100111

32
Signed numbers using 2’s complement.
Exercise 6.
Express the decimal number -39 as an 8-bit number using 2’s complement

33
Signed numbers using 2’s complement.
Exercise 6.
Express the decimal number -39 as an 8-bit number using 2’s complement

11011001

-2^7 + 2^6 + 2^4 + 2^3 + 2^0= -128+64+16+8+1=-39

34
The decimal value of signed numbers
Decimal values of positive and negative numbers in the 2’s complement form are determined
by summing the weights in all bit positions where there are 1s and ignoring those positions
where there are zeros.

The weight of the sign bit in a negative number is given a negative value.

35
The decimal value of signed numbers.
Example
Determine the decimal values of the signed binary numbers expressed in 2’s complement:
a) 01010110 b) 10101010

36
The decimal value of signed numbers.
Example
Determine the decimal values of the signed binary numbers expressed in 2’s complement:
a) 01010110 b) 10101010

37
Arithmetic Operations with Signed Numbers
Addition
There are four cases that can occur when two signed binary numbers are added.

1. Both numbers positive


2. Positive number with magnitude larger than negative number
3. Negative number with magnitude larger than positive number
4. Both numbers negative

38
Arithmetic Operations with Signed Numbers
Addition

39
Arithmetic Operations with Signed Numbers
Addition

40
Overflow condition
When two numbers are added and the number of bits required to represent the sum
exceeds the number of bits in the two numbers, an overflow results as indicated by an
incorrect sign bit.

An overflow can occur only when both numbers are positive or both numbers are negative.

If the sign bit of the result is different than the sign bit of the numbers that are added, overflow
is indicated.

41
Subtraction of signed numbers
Subtraction is a special case of addition. For example, subtracting +6 (the subtrahend) from
+9 (the minuend) is equivalent to adding -6 to +9.

Basically, the subtraction operation changes the sign of the subtrahend and adds it to the
minuend. The result of a subtraction is called the difference.

42
Subtraction of signed numbers
Perform each of the following subtractions of the signed numbers:
a) 00001000 – 00000011 b) 00001100 – 11110111
c) 11100111 – 00010011 d) 10001000 -- 11100010

43
Subtraction of signed numbers
Perform each of the following subtractions of the signed numbers:
a) 00001000 – 00000011 b) 00001100 – 11110111
c) 11100111 – 00010011 d) 10001000 -- 11100010

44
Subtraction of signed numbers
Perform each of the following subtractions of the signed numbers:
a) 00001000 – 00000011 b) 00001100 – 11110111
c) 11100111 – 00010011 d) 10001000 - 11100010

45
Multiplication of signed numbers
Multiply the signed binary numbers: 01010011 (multiplicand) and 11000101 (multiplier)

46
Multiplication of signed numbers
Multiply the signed binary numbers: 01010011 (multiplicand) and 11000101 (multiplier)

47
Multiplication of signed numbers
Multiply the signed binary numbers: 01010011 (multiplicand) and 11000101 (multiplier)

48
Division of signed numbers
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; the quotient is the number of times that the
divisor will go into the dividend. This means that the divisor can be subtracted from the
dividend a number of times equal to the quotient

The divisor was subtracted from the dividend


three times before a remainder of zero was
obtained.

Therefore, the quotient is 3

49
Division of signed numbers
Divide 01100100 by 00011001

50
Division of signed numbers
Divide 01100100 by 00011001

51
Division of signed numbers
Divide 01100100 by 00011001

52
Hexadecimal numbers

Base of 16. It is composed of 16


numeric and alphabetic characters

Each hexadecimal digit represents a 4-bit binary


number

How do you count in hexadecimal once you get to


F?

Simply start over with another column:


..., E, F, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 1A,
1B, 1C, 1D, 1E, 1F, 20, 21, 22, 23, 24, 25, 26, 27,
28, 29, 2A, 2B, …
53
Binary to hexadecimal conversion
Convert the following binary numbers to hexadecimal: a) 1100101001010111
b) 111111000101101001

54
Hexadecimal to Binary conversion
Determine the binary numbers for the following hexadecimal numbers:
a) 10A4 b) CF8E c) 9742

55
Hexadecimal to decimal conversion
Convert the following hexadecimal numbers to decimal: a) 1C b) A85

56
Decimal to hexadecimal conversion
Convert the decimal number 650 to hexadecimal by repeated division by 16.

57
Hexadecimal addition
Add the following hexadecimal numbers: (a) 23 + 16 (b) 58 + 22 (c) 2B + 84 (d) DF + AC

58
Hexadecimal subtraction
Subtract the following hexadecimal numbers: a) 84 - 2A b) C3 - 0B
Convert the hexadecimal number to binary. Take the 2’s complement of the binary number.

59
Digital Codes
Many specialized codes are used in digital systems.

Some codes are strictly numeric, like Binary coded decimal (BCD), and others are
alphanumeric; that is, they are used to represent numbers, letters, symbols, and
Instructions, like ASCII.

60
Binary coded decimal (8421 BCD)
Binary coded decimal (BCD) is a way to express each of the decimal digits with a binary
code.

The six code combinations that are not used—1010, 1011, 1100, 1101, 1110, and 1111—are
invalid in the 8421 BCD code.

Digital clocks, digital thermometers, digital meters, and other devices with seven-segment
displays typically use BCD code to simplify the displaying of decimal numbers.

61
Decimal to BCD conversion
Convert each of the following decimal numbers to BCD:
a) 35 (b) 98 (c) 170 (d) 2469

Numeric keypad

62
BCD to decimal conversion
Convert each of the following BCD codes to decimal:
(a) 10000110 (b) 001101010001 (c) 1001010001110000

63
ASCII
Abbreviation for American Standard Code for Information Interchange.

ASCII is a universally accepted alphanumeric code used in most computers and other
electronic equipment. Most computer keyboards are standardized with the ASCII.

When you enter a letter, a number, or control command, the corresponding ASCII code goes
into the computer.

ASCII has 128 characters and symbols represented by a 7-bit binary code. Actually, ASCII
can be considered an 8-bit code with the MSB always 0. This 8-bit code is 00 through 7F in
hexadecimal.

The first thirty-two ASCII characters are nongraphic commands that are never printed or
displayed and are used only for control purposes.

64
ASCII table

65
Error codes: Parity bit

66
67

You might also like