DLD Chapter2
DLD Chapter2
1
Introduction to Numbering System
Decimal Numbers
In the decimal number system each of the ten digits 0 through 9 represents a
certain quantity.
The base(radix) of decimal numbers is 10.
The position of each digit in a weight number system is assigned a weight
based on the base of the system.
Powers of ten that increase from right to the column weights of decimal
numbers are left beginning with 10^0 , 10^1 , 10^2,10^3 ...
Decimal Numbers
For fractional decimal numbers, the column weights are negative powers of ten
that decrease from left to right.
Decimal numbers can be expressed as the sum of the products of each digit times
the column values for that digit.
Example
Binary Numbers
1. 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.
Repeated Division-by-2 Method
16
Binary Arithmetic
Binary arithmetic is essential in all digital computers and in many other
types of digital systems.
To understand digital systems, you must know the basics of binary
addition, subtraction, multiplication, and division.
This section provides an introduction that will be expanded in later
sections.
20
Example
21
Example 2
22
Solution
23
Binary Multiplication
24
Example
25
Binary Division Example
26
Checkup
1. Perform the following binary additions:
(a) 1101 + 1010
(b) 10111 + 01101
2. Perform the following binary subtractions:
(a) 1101 - 0100
(b) 1001 - 0111
Perform the indicated binary operations:
(a) 110 * 111
(b) 1100 , 011
27
1’S And 2’S 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.
After completing this section, you should be able to
Convert a binary number to its 1’s complement
Convert a binary number to its 2’s complement using either of two method
28
Finding the 1’s Complement
29
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.
30
Example
31
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 the32sign-
magnitude is the least used.
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.
A 0 sign bit indicates A positive number, and A 1 sign
bit indicates A negative number.
33
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.
For example, the decimal number +25 is expressed as an 8-bit signed
binary number using the sign-magnitude form as
34
Cont’d
35
1’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.
For example, using eight bits, the decimal number -25 is
expressed as the 1’s complement of +25 (00011001) as 11100110
The 1’s complement form, a negative number is the 1’s complement of the
corresponding positive number.
36
2’s Complement Form
Positive numbers in 2’s complement form are represented the same way as in the sign
magnitude and 1’s complement forms.
Negative numbers are the 2’s complements of the corresponding positive numbers.
Again, using eight bits, let’s take decimal number -25 and express it as the 2’s complement of
+25 (00011001).
Inverting each bit and adding 1, you get
-25 = 11100111
in the 2’s complement form, a negative number is the 2’s complement of the corresponding
positive number
37
Arithmetic Operations With Signed
Numbers
Addition
The two numbers in an addition are the addend and the augend. The result is the sum.
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
Let’s take one case at a time using 8-bit signed numbers as examples. The equivalent
decimal numbers are shown for reference.
38
39
40
Hexadecimal Numbers
The hexadecimal number system has a base of sixteen; that is, it is composed of 16
numeric and alphabetic characters.
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.
41
Hexadecimal
Numbers
42
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.
43
Example
44
Hexadecimal-to-binary
Conversion
To convert from a hexadecimal number to a binary
number, reverse the process and replace each
hexadecimal symbol with the appropriate four bits.
45
Example
46
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.
47
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
48
Example
49
Decimal-to-Hexadecimal
Conversion
Repeated division of a decimal number by 16 will produce the
equivalent hexadecimal number, formed by the remainders of
the divisions.
The first remainder produced is the least significant digit
(LSD).
Each successive division by 16 yields a remainder that
becomes a digit in the equivalent hexadecimal number.
50
Example
51
Hexadecimal addition
Addition can be done directly with hexadecimal numbers by remembering
that the hexadecimal digits 0 through 9 are equivalent to decimal digits 0
through 9 and that hexadecimal digits A through F are equivalent to decimal
numbers 10 through 15.
When adding two hexadecimal numbers, use the following rules. (Decimal
numbers are indicated by a subscript 10.)
1. In any given column of an addition problem, think of the two
hexadecimal digits in
terms of their decimal values. For instance, 516 = 510 and C16 =
1210.
2. If the sum of these two digits is 1510 or less, bring down the
corresponding hexadecimal digit.
3. If the sum of these two digits is greater than 1510, bring down the
amount of the sum 52
53
Exercise
Add 4C16 and 3A16
54
Binary Coded Decimal (BCD)
55
The 8421 BCD Code
56
Invalid Codes
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.
57
Example
58
Applications of BCD
59
BCD addition
BCD is a numerical code and can be used in arithmetic operations.
Addition is the most important operation because the other three operations (subtraction,
multiplication, and division) can be accomplished by the use of addition.
61
Cont’d
62
Exercise
1. Convert hexadecimal number 4100 to binary:
2. Convert binary number 1111110000 to hexadecimal:
3. Convert hexadecimal number F3 to decimal:
4. Convert decimal number 6500 to hexadecimal:
5. Perform the additions hexadecimal number: A0 + 6B
6. Add the following BCD numbers:
A. 01010001 + 01011000
B. 10011000 + 10010111
63
End Of The Chapter
64