Isbn 978-1-29202-561-2
Isbn 978-1-29202-561-2
Digital Electronics
A Practical Approach with VHDL
William Kleitz
Ninth Edition
Kleitz
Ninth Edition
ISBN 978-1-29202-561-2
9 781292 025612
Pearson Education Limited
Edinburgh Gate
Harlow
Essex CM20 2JE
England and Associated Companies throughout the world
All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmitted
in any form or by any means, electronic, mechanical, photocopying, recording or otherwise, without either the
prior written permission of the publisher or a licence permitting restricted copying in the United Kingdom
issued by the Copyright Licensing Agency Ltd, Saffron House, 610 Kirby Street, London EC1N 8TS.
All trademarks used herein are the property of their respective owners. The use of any trademark
in this text does not vest in the author or publisher any trademark ownership rights in such
trademarks, nor does the use of such trademarks imply any afliation with or endorsement of this
book by such owners.
2 Twos-Complement Representation
The most widely used method of representing binary numbers and performing arith-
metic in computer systems is by using the twos-complement method. With this
method, both positive and negative numbers can be represented using the same format,
and binary subtraction is greatly simplified.
All along we have seen representing binary numbers in groups of eight for a
reason. Most computer systems are based on 8- or 16-bit numbers. In an 8-bit system,
the total number of different combinations of bits is 256 (28); in a 16-bit system, the
number is 65,536 (216).
To be able to represent both positive and negative numbers, the twos-complement
format uses the most significant bit (MSB) of the 8- or 16-bit number to signify
whether the number is positive or negative. The MSB is therefore called the sign bit
and is defined as 0 for positive numbers and 1 for negative numbers. Signed twos-
complement numbers are shown in Figure 4.
Sign bit
(a)
Sign bit
(b)
The range of positive numbers in an 8-bit system is 0000 0000 to 0111 1111 (0
to 127). The range of negative numbers is 1111 1111 to 1000 0000 (-1 to -128). In
general, the maximum positive number is equal to 2N - 1 - 1, and the maximum nega-
tive number is -(2N - 1), where N is the number of bits in the number, including the
sign bit (e.g., for an 8-bit positive number, 28 - 1 - 1 = 127).
A table of twos-complement numbers can be developed by starting with some
positive number and continuously subtracting 1. Table 3 shows the signed twos-com-
plement numbers from +7 to -8.
Converting a decimal number to twos complement, and vice versa, is simple
and can be done easily using logic gates, as we will see later in this chapter. For now,
lets deal with 8-bit numbers; however, the procedure for 16-bit numbers is exactly
the same.
277
ARITHMETIC OPERATIONS AND CIRCUITS
EXAMPLE 5
Common
Misconception
Convert +3510 to twos complement.
As soon as some students
see the phrase convert to
Solution:
twos complement, they go True binary = 0010 0011
ahead with the procedure
for negative numbers
Twos complement = 0010 0011 Answer
whether the original
number is positive or
negative.
EXAMPLE 6
278
ARITHMETIC OPERATIONS AND CIRCUITS
EXAMPLE 7
EXAMPLE 8
EXAMPLE 9
Review Questions
4. Which bit in an 8-bit twos-complement number is used as the sign bit?
5. Are the following twos-complement numbers positive or negative?
(a) 1010 0011
(b) 0010 1101
(c) 1000 0000
3 Twos-Complement Arithmetic
All four of the basic arithmetic functions involving positive and negative numbers can
be dealt with very simply using twos-complement arithmetic. Subtraction is done by
279
ARITHMETIC OPERATIONS AND CIRCUITS
adding the two twos-complement numbers. Thus, the same digital circuitry can be
used for additions and subtractions, and there is no need always to subtract the smaller
number from the larger number. We must be careful, however, not to exceed the
maximum range of the twos-complement number: +127 to -128 for 8-bit systems,
and +32,767 to -32,768 for 16-bit systems (+2N - 1 - 1 to -2N - 1).
When adding numbers in the twos-complement form, simply perform a regular
binary addition to get the result. When subtracting numbers in the twos-complement
form, convert the number being subtracted to a negative twos-complement number
and perform a regular binary addition [e.g., 5 - 3 = 5 + (-3)]. The result will be a
twos-complement number, and if the result is negative, the sign bit will be 1.
Work through the following examples to familiarize yourself with the addition
and subtraction procedure.
EXAMPLE 10
EXAMPLE 11
280
ARITHMETIC OPERATIONS AND CIRCUITS
Review Questions
6. Which of the following decimal numbers cannot be converted to 8-bit
twos-complement notation?
(a) 89
(b) 135
(c) -107
(d) -144
7. The procedure for subtracting numbers in twos-complement notation is
exactly the same as for adding numbers. True or false?
8. When subtracting a smaller number from a larger number in twos com-
plement, there will always be a carry-out of the MSB, which will be
ignored. True or false?
4 Hexadecimal Arithmetic*
Hexadecimal representation is a method of representing groups of 4 bits as a single
digit. Hexadecimal notation has been widely adopted by manufacturers of computers
and microprocessors because it simplifies the documentation and use of their equip-
ment. Eight- and 16-bit computer system data, program instructions, and addresses use
hexadecimal to make them easier to interpret and work with than their binary equiva-
lents.
Hexadecimal Addition
Remember, hexadecimal is a base 16 numbering system, meaning that it has 16 differ-
ent digits (as shown in Table 4). Adding 3 + 6 in hex equals 9, and 5 + 7 equals C.
But, adding 9 + 8 in hex equals a sum greater than F, which will create a carry. The
sum of 9 + 8 is 1710, which is 1 larger than 16, making the answer 1116.
*
Most scientific calculators perform number base conversions and arithmetic. This allows you to enter binary, octal, decimal, or
hexadecimal numbers and perform any of the arithmetic operations. In this chapter we will learn the step-by-step procedures for
performing these operations by hand, but as the numbers get more complex it is best to use your calculator for these functions.
281