Download presentation
Presentation is loading. Please wait.
Published byMaría Victoria Méndez Ortíz Modified over 6 years ago
1
Number Systems and Codes (parte 1)
Digital systems are built from circuits that process binary digits—0s and 1s—yet very few real-life problems are based on binary numbers or any numbers at all. Therefore, a digital system designer must establish some correspondence between the binary digits processed by digital circuits and real-life numbers, events, and conditions. The purpose of this chapter is to show you how familiar numeric quantities can be represented and manipulated in a digital system, and how nonnumeric data, events, and conditions also can be represented. Sistemas Digitales I C. Sisterna Sistemas Digitales I
2
Positional Number Systems
A number is represented by a string of digits where each digit position has an associated weight In general, a number D of the form d1d0 . d-1d-2 has the value Base or Radix (in this case the base is 10) Positional Number Systems The traditional number system that we learned in school and use every day in business is called a positional number system. In such a system, a number is represented by a string of digits where each digit position has an associated weight. The value of a number is a weighted sum of the digits, for example: 1734 = 1· · ·10 + 4·1 Each weight is a power of 10 corresponding to the digit’s position. A decimal point allows negative as well as positive powers of 10 to be used: = 5· · ·10 + 5·1 + 6· ·0.01 In general, a number D of the form d1d0.d-1d-2 has the value D = d1·101 + d0·100 + d–1·10–1 + d–2·10–2 Here, 10 is called the base or radix of the number system. In a general positional number system, the radix may be any integer r ≥ 2, and a digit in position i has weight ri. The general form of a number in such a system is dp–1dp–2· · ·d1d0 . d–1d–2· · ·d–n where there are p digits to the left of the point and n digits to the right of the point, called the radix point. If the radix point is missing, it is assumed to be to the right of the rightmost digit. The value of the number is the sum of each digit multiplied by the corresponding power of the radix: The radi ‘r’ should be indicated in The base as a subscript after the number to prevent confusion when working in more than one base. The value of the number is the sum of each digit multiplied by the corresponding power of the radix r C. Sisterna Sistemas Digitales I
3
Positional Number Systems
The general form of a number in positional system is where there are p digits to the left of the point and n digits to the right of the point, called the radix point. If the radix point is missing, it is assumed to be to the right of the rightmost digit. The value of the number is the sum of each digit multiplied by the corresponding power of the radix Positional Number Systems The traditional number system that we learned in school and use every day in business is called a positional number system. In such a system, a number is represented by a string of digits where each digit position has an associated weight. The value of a number is a weighted sum of the digits, for example: 1734 = 1· · ·10 + 4·1 Each weight is a power of 10 corresponding to the digit’s position. A decimal point allows negative as well as positive powers of 10 to be used: = 5· · ·10 + 5·1 + 6· ·0.01 In general, a number D of the form d1d0.d-1d-2 has the value D = d1·101 + d0·100 + d–1·10–1 + d–2·10–2 Here, 10 is called the base or radix of the number system. In a general positional number system, the radix may be any integer r ≥ 2, and a digit in position i has weight ri. The general form of a number in such a system is dp–1dp–2· · ·d1d0 . d–1d–2· · ·d–n where there are p digits to the left of the point and n digits to the right of the point, called the radix point. If the radix point is missing, it is assumed to be to the right of the rightmost digit. The value of the number is the sum of each digit multiplied by the corresponding power of the radix: The radix ‘r’ should be indicated in The base as a subscript after the number to prevent confusion when working in more than one base. i C. Sisterna Sistemas Digitales I
4
Range of Representation – Decimal Numbers
An N-digit decimal number represents one of 10N possibilities: 0, 1, 2, 3, …, 10N − 1. This is called the range of the number. For example, a three-digit decimal number represents one of 1000 possibilities in the range of 0 to 999. C. Sisterna Sistemas Digitales I
5
Binary Number System A number in a binary system is made up of bits.
Each bit can have only two values ‘0’ or ‘1’. In a binary number system the base (radix) is equal to 2 Bits represent one of two values, 0 or 1, and are joined together to form binary numbers. Each column of a binary number has twice the weight of the previous column, so binary numbers are base 2. In binary the column weights (again from right to left) are 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, and so on. If you work with binary numbers often, you’ll save time if you remember these powers of two up to 216. An N-bit binary number represents one of 2N possibilities: 0, 1, 2, 3, …, 2N - 1. Table 1.1 shows 1, 2, 3, and 4-bit binary numbers and their decimal equivalents. = LSB: least significant bit MSB: most significant bit C. Sisterna Sistemas Digitales I
6
Range of Representation – Binary Numbers
An N-bit binary number represents one of 2N possibilities: 0, 1, 2, 3, …, 2N - 1 Which is the range of representation of an 3-bits binary number? Which is the range of representation of an 4-bits binary number? Which is the range of representation of an 8-bits binary number? Which is the range of representation of an 64-bits binary number? C. Sisterna Sistemas Digitales I
7
Binary Number System C. Sisterna Sistemas Digitales I
8
Hexadecimal Number System
Writing long binary numbers becomes tedious and prone to error. In the Hexadecimal number system the bits of a binary number is grouped in 4 bits, according the following table: Writing long binary numbers becomes tedious and prone to error. A group of four bits represents one of 24 = 16 possibilities. Hence, it is sometimes more convenient to work in base 16, called hexadecimal. Hexadecimal numbers use the digits 0 to 9 along with the letters A to F, as shown in Table 1.2. Columns in base 16 have weights of 1, 16, 162 (or 256), 163 (or 4096), and so on. C. Sisterna Sistemas Digitales I
9
Hexadecimal Number System
C. Sisterna Sistemas Digitales I
10
Hexadecimal Number System
Writing long binary numbers becomes tedious and prone to error. 6 3 6 8 B A A D 6368BAAD16 C. Sisterna Sistemas Digitales I
11
Hexadecimal Number System
How do you count in hexadecimal once you get to F? Simply start over with another column and continue as follows: … , 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, 2C, 2D, 2E, 2F, 30, 31,… C. Sisterna Sistemas Digitales I
12
To convert from any base r to decimal base:
Converting Numbers To convert from any base r to decimal base: i 7CABD16 = = = 23104 = FE11116 = = C. Sisterna Sistemas Digitales I
13
To convert from decimal base to any base r
Converting Numbers To convert from decimal base to any base r The decimal number has to be divided by the base r, the reminder divided again, until there no more division possible 21710 = ?????2 21710 / 2 = 108 remainder 1 LSB 10810 / 2 = 54 remainder 0 21710 = 5410 / 2 = 27 remainder 0 2710 / 2 = 13 remainder 1 1310 / 2 = 6 remainder 1 610 / 2 = 3 remainder 0 310 / 2 = 1 remainder 1 110 / 2 = 1 remainder 1 MSB C. Sisterna Sistemas Digitales I
14
Converting Numbers C. Sisterna Sistemas Digitales I
15
Converting Numbers 2496410 = xxxxx16 2496410 = xxxxx2 ????
C. Sisterna Sistemas Digitales I
16
Converting Numbers - Resume
C. Sisterna Sistemas Digitales I
17
Binary Arithmetic C. Sisterna Sistemas Digitales I
18
Binary Addition and Substraction
C. Sisterna Sistemas Digitales I
19
Binary Addition X Y Cin Cout Cin Cout S
Addition and subtraction of nondecimal numbers by hand uses the same technique that we learned in grammar school for decimal numbers; the only catch is that the addition and subtraction tables are different. Table in the slide is the addition table for binary digits. To add two binary numbers X and Y, we add together the least significant bits with an initial carry (cin) of 0, producing carry (cout) and sum (s) bits according to the table. We continue processing bits from right to left, adding the carry out of each column into the next column’s sum. Two examples of decimal additions and the corresponding binary additions are shown in in the slide, using a colored arrow to indicate a carry of 1, with the carries shown as a bit string C. C. Sisterna Sistemas Digitales I
20
Binary Addition C. Sisterna Sistemas Digitales I
21
Binary Substraction bin x y d bout
Binary subtraction is performed similarly, using borrows (bin and bout) instead of carries between steps, and producing a difference bit d. Two examples of decimal subtractions and the corresponding binary subtractions are shown in Figure 2-2. As in decimal subtraction, the binary minuend values in the columns are modified when borrows occur, as shown by the colored arrows and bits. The examples from the figure are repeated below along with two more, this time showing the borrows as a bit string B: Bin: borrow in / Bout: borrow out (borrow = pedido) C. Sisterna Sistemas Digitales I
22
Challenge 16 16 16 16 16 C. Sisterna Sistemas Digitales I
23
Representation of Negative Numbers
C. Sisterna Sistemas Digitales I
24
Representation of Negative Numbers
- Signed Magnitude - Complement to the Base minus one - Complement to the Base So far, we have dealt only with positive numbers, but there are many ways to represent negative umbers. In everyday business, we use the signed-magnitude system, discussed next. However, most computers use one of the complement number systems that we introduce later. C. Sisterna Sistemas Digitales I
25
Signed-Magnitude Representation
Number 0 = positive 1 = negative An extra bit is used to represent the sign (the sign bit) Signed-Magnitude Representation In the signed-magnitude system, a number consists of a magnitude and a symbol indicating whether the magnitude is positive or negative. Thus, we interpret decimal numbers +98, -57, , and -13 in the usual way, and we also assume that the sign is “+” if no sign symbol is written. There are two possible representations of zero, “+0” and “-0”, but both have the same value. The signed-magnitude system is applied to binary numbers by using an extra bit position to represent the sign (the sign bit). Traditionally, the most significant bit (MSB) of a bit string is used as the sign bit (0 = plus, 1 = minus), and the lower-order bits contain the magnitude. WARNING ! 21310 In a binary number representation is fundamental to know how many bits are used to represent a number C. Sisterna Sistemas Digitales I
26
Signed Magnitude Representation - Range
+(2n-1 -1) <= Number <= -(2n-1 -1) n = number of bits to represent a number Double representation for ‘0’ = +0 = - 0 The signed-magnitude system has an equal number of positive and negative integers. An n-bit signed-magnitude integer lies within the range -(2n-1-1) through +(2n-1-1), and there are two possible representations of zero. Now suppose that we wanted to build a digital logic circuit that adds signed-magnitude numbers. The circuit must examine the signs of the addends to determine what to do with the magnitudes. If the signs are the same, it must add the magnitudes and give the result the same sign. If the signs are different, it must compare the magnitudes, subtract the smaller from the larger, and give the result the sign of the larger. All of these “ifs,” “adds,” “subtracts,” and “compares” translate into a lot of logic-circuit complexity. Adders for complement number systems are much simpler, as we’ll show next. Perhaps the one redeeming feature of a signed-magnitude system is that, once we know how to build a signed-magnitude adder, a signed-magnitude subtractor is almost trivial to build—it need only change the sign of the subtrahend and pass it along with the minuend to an adder . Main disadvantage: complex math operation circuits C. Sisterna Sistemas Digitales I
27
Complement Number System
While the signed-magnitude system negates a number by changing its sign, a complement number system negates a number by taking its complement as defined by the system Taking the complement of a number is more difficult than changing the sign, but two numbers in a complement number system can be added or subtracted directly without the sign and magnitude checks required by the signed magnitude system Complement Number Systems While the signed-magnitude system negates a number by changing its sign, a complement number system negates a number by taking its complement as defined by the system. Taking the complement is more difficult than changing the sign, but two numbers in a complement number system can be added or subtracted directly without the sign and magnitude checks required by the signed magnitude system. We shall describe two complement number systems, called the “radix complement” and the “diminished radix-complement.” Two’s complement (radix complement, complemento a dos, complemento a la base) Binary number system One’s complement (diminished radix-complement, complement a uno, complemento a la base menos 1) C. Sisterna Sistemas Digitales I
28
Two’s Complement (complemento a dos)
Practical method to obtain the two’s compement of a binary number 1710 = bit to bit complement 9910 = bit to bit complement = ???????2 - = ???????2 - __________ __________ C. Sisterna Sistemas Digitales I
29
Two’s Complement – Range of Representation
+(2n-1 -1) <= Number <= -(2n-1) The decimal equivalent for a two’s-complement binary number is computed the same way as for an unsigned number, except that the weight of the MSB is -2n-1 instead of +2n-1 For binary numbers, the radix complement is called the two’s complement. The MSB of a number in this system serves as the sign bit; a number is negative if and only if its MSB is 1. The decimal equivalent for a two’s-complement binary number is computed the same way as for an unsigned number, except that the weight of the MSB is -2n-1 instead of +2 n-1. The range of representable numbers is -(2 n-1) through +(2 n-1 -1) C. Sisterna Sistemas Digitales I
30
Tow’s Complement – Representation of ‘0’
In the two’s-complement number system, zero is considered positive because its sign bit is 0 A carry out of the MSB position occurs in one case, as shown in color above. As in all two’s-complement operations, this bit is ignored and only the low-order n bits of the result are used. In the two’s-complement number system, zero is considered positive because its sign bit is 0. Since two’s complement has only one representation of zero, we end up with one extra negative number, -(2 n-1), that doesn’t have a positive counterpart. Since two’s complement has only one representation of zero, there is one extra negative number, -(2n-1) C. Sisterna Sistemas Digitales I
31
Two’s Complement Addition
The addition of two positive binary numbers represented in two’s complement is done bit by bit, like any other addition The result will always be the correct sum, as long as the range of the number system is not exceeded C. Sisterna Sistemas Digitales I
32
Two’s Complement Susbstraction
The substraction in two’s complement is done by adding the negative numbre (represented in two’s complement) The result will always be the correct sum, as long as the range of the number system is not exceeded C. Sisterna Sistemas Digitales I
33
Overflow (Desbordamiento)
Overlfow ocurres when the addition operation produces a result that exceed the range of the number system There is a simple rule for detecting overflow in addition If an addition operation produces a result that exceeds the range of the number system, overflow is said to occur. In the modular counting representation of Figure 2-3, overflow occurs during addition of positive numbers when we count past +7. Addition of two numbers with different signs can never produce overflow, but addition of two numbers of like sign can, as shown by the following examples: Fortunately, there is a simple rule for detecting overflow in addition: An addition overflows if the signs of the addends are the same and the sign of the sum is different from the addends’ sign. The overflow rule is sometimes stated in terms of carries generated during the addition operation: An addition overflows if the carry bits cin into and cout out of the sign position are different. Close examination of Table 2-3 on page 28 shows that the two rules are equivalent—there are only two cases where cin ≠ cout, and these are the only two cases where x = y and the sum bit is different An addition overflows if the signs of the addends are the same and the sign of the sum is different from the addends’ sign (An addition overflows if the carry bits cin into and cout out of the sign position are different ) C. Sisterna Sistemas Digitales I
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.