Chapter 2 Numeric Representation., Exams of Number Theory

To answer that, we must first understand binary. 2.1 Binary. Binary, like decimal, is a positional number system. This means that numbers are represented by a.

Typology: Exams

2022/2023

Uploaded on 02/28/2023

mortimer
mortimer 🇺🇸

4.4

(5)

214 documents

1 / 9

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Chapter 2 Numeric Representation.
Most of the things we encounter in the world around us are analog; they don’t just take on one of
two values. How then can they be represented digitally? The key is that multiple signals can be
grouped to represent a single quantity. A group of two or more signals is called a bus (or multi-bit
signal). A bus consisting of two signals is called a 2-bit bus, and it can take on one of four values:
low-low, low-high, high-low and high-high. A 3-bit bus can take on eight distinct values, and in
general, an n-bit bus can take on 2n distinct values.
The next question, then, is how can we make those 2n values correlate to real-world signals? To
answer that, we must first understand binary.
2.1 Binary
Binary, like decimal, is a positional number system. This means that numbers are represented by a
sequence of symbols, and that the significance of each symbol depends both on its position and the
base of the number system. Decimal numbers are base 10 and the symbols are called digits. Binary
numbers are base 2 and the symbols are called bits.
Any positive integer can be represented in a positional number system by a sequence of symbols
and a base. Specifically, a positive integer in base b that has m symbols is written:
Sm-1 Sm-2 S1S0 b. (2.1)
The base is written in subscript and should be included with the number unless it is in decimal or
the base is clear from context. A number, N, in this positional form can be evaluated using the
expansion:
N = Sm-1 x b m-1 + … + S1 x b 1 + S0 x b0 (2.2)
Example 2.1. Find the decimal equivalents of 11012 and 7348.
Solution: Using equation 1.2, 11012 and 7348 expand to:
11012 = 1 x 23 + 1 x 22 + 0 x 21 + 1 x 20 = 8 + 4 + 1 = 13
7348 = 7 x 82 + 3 x 81 + 4 x 80 = 7 x 64 + 3 x 8 + 4 x 1 = 476
pf3
pf4
pf5
pf8
pf9

Partial preview of the text

Download Chapter 2 Numeric Representation. and more Exams Number Theory in PDF only on Docsity!

Chapter 2 Numeric Representation.

Most of the things we encounter in the world around us are analog; they don’t just take on one of two values. How then can they be represented digitally? The key is that multiple signals can be grouped to represent a single quantity. A group of two or more signals is called a bus (or multi-bit signal). A bus consisting of two signals is called a 2-bit bus, and it can take on one of four values: low-low, low-high, high-low and high-high. A 3-bit bus can take on eight distinct values, and in general, an n - bit bus can take on 2 n^ distinct values. The next question, then, is how can we make those 2 n^ values correlate to real-world signals? To answer that, we must first understand binary.

2.1 Binary

Binary, like decimal, is a positional number system. This means that numbers are represented by a sequence of symbols, and that the significance of each symbol depends both on its position and the base of the number system. Decimal numbers are base 10 and the symbols are called digits. Binary numbers are base 2 and the symbols are called bits. Any positive integer can be represented in a positional number system by a sequence of symbols and a base. Specifically, a positive integer in base b that has m symbols is written: Sm- 1 Sm- 2S 1 S (^0) b. ( 2 .1) The base is written in subscript and should be included with the number unless it is in decimal or the base is clear from context. A number, N , in this positional form can be evaluated using the expansion: N = Sm - 1 x b m -^1 + … + S 1 x b^1 + S 0 x b^0 ( 2 .2) Example 2 .1. Find the decimal equivalents of 11012 and 734 8. Solution: Using equation 1.2, 1101 2 and 734 8 expand to: 11012 = 1 x 23 + 1 x 22 + 0 x 21 + 1 x 20 = 8 + 4 + 1 = 13 7348 = 7 x 82 + 3 x 81 + 4 x 80 = 7 x 64 + 3 x 8 + 4 x 1 = 476

The powers of b in equation 1.2 are called weights. Symbols with larger weights are more significant than those with smaller weights. The leftmost symbol is the most significant of all. In decimal, this is called the most significant digit. In binary it is called the most significant bit. Similarly, the rightmost symbol is called the least significant digit , or the least significant bit , depending on the base. Positional numbering systems can be extended to fractions by adding a radix point and additional symbols: Sm- 1 Sm- 2S 1 S 0. S - 1 S - 2 … (^) b ( 2 .3) In decimal or binary, the radix point is called the decimal point or the binary point , respectively. The equation for evaluating positional numbers with a fractional part is similar to that for integers: N = Sm - 1 x b m -^1 + … + S 1 x b^1 + S 0 x b^0 + S - 1 x b -^1 + S - 2 x b -^2 … ( 2 .4) Example 2 .2. Convert 1.011 2 and 3.14 5 to decimal. Solution: Using equation 1. 4 , 1.01 12 and 3.14 5 expand to: 1 .01 12 = 1 x 20 + 0 x 2 -^1 + 1 x 2 -^2 + 1 x 2 -^3 = 1 + ଵ ସ

ଵ ଼

ଷ ଼

3.14 5 = 3 x 50 + 1 x 5 -^1 + 4 x 5 -^2 = 3 + ଵ ହ +^ ସ ଶହ =^3 ଽ ଶହ =^ 3. There is an easier technique to convert a binary number to decimal. Start by writing the binary number down, then write a weight of 1 above the 1’s bit (just left of the binary point). Double the weight for each bit left of the 1’s bit and halve it for each bit to the right. Finally, get the decimal equivalent by adding together all the weights that have a 1 beneath them. For example, to use this technique to convert 10110.101 2 to decimal, we would write down the binary number and write the weight of each bit above it: Weight: 16 8 4 2 1 0.5 0.25 0. Binary Number: 1 0 1 1 0. 1 0 1 The sum the weights that that have a 1 beneath them is 16+4+2+0.5+0.125 = 22.625. Example 2 .3. Convert 110100102 to decimal. Solution: Write down the binary number and write the weight of each bit above it. Since there is no binary point, we start with the rightmost bit. Weight: 128 64 32 16 8 4 2 1 Binary Number: 1 1 0 1 0 0 1 0 Sum the weights that that have a 1 beneath them: 128+64+16+2 = 210

2.2 Hexidecimal

It should now be clear that binary is the ideal numeric representation for digital circuitry. Each bit must either be 1 or 0 just as each signal must either be high or low. Binary is not, however, a convenient representation for humans. Digital computers, for example, routinely deal with 32-bit and 64-bit numbers. Writing down a number of this size with ones and zeros would be awkward to say the least. What we need is a number system with a richer set of symbols that still corresponds directly to digital signals, and that is exactly what the hexadecimal (base 16) number system provides. Because hexadecimal is base 16, it requires 16 symbols. We use the familiar 0-9 for the first ten symbols and hijack the first six letters of the English alphabet for the rest. The utility of hexadecimal (or hex) stems from the fact that 16 = 2^4. This means that a hexadecimal digit comprises exactly four bits, which makes conversion from binary almost trivial. To convert a binary number to hex, group the bits four at a time (padding with zeros if necessary), starting at the binary point. Then replace each group with the corresponding hexadecimal digit from Table 1-2. Table 1-2 Binary and Decimal Representation of Hexadecimal Digits Hex Binary Decimal Hex Binary Decimal 0 0000 0 8 1000 8 1 0001 1 9 1001 9 2 0010 2 A 1010 10 3 0011 3 B 1011 11 4 0100 4 C 1100 12 5 0101 5 D 1101 13 6 0110 6 E 1110 14 7 0111 7 F 1111 15 Example 2. 6. Convert 10110110100.011011 2 to hexadecimal. Solution: Group bits, four at a time, starting at the binary point. 101 1011 0100. 0110 11 The leftmost and rightmost groups have fewer than four bits, so pad them with zeros. 0101 1011 0100. 0110 1100 Replace the groups with hexadecimal digits from Table 1- 2 : 5B4.6C 16 Converting a number from hexadecimal to binary is equally easy. Simply replace each hexadecimal digit with its binary equivalent from Table 1-2.

Example 2. 7. Convert 3D.7A 16 to binary. Solution: Replace each hexadecimal digit with its binary equivalent. 0011 1101. 0111 1010 Discard unnecessary zeros: 111101.0111101 2

2.3 Two’s Complement

Binary representation works well for positive numbers, but what about negative numbers? How can they be represented with digital signals? One approach is to dedicate one bit, called the sign bit, to indicate whether or not a number is negative. Despite the nuisance of having both a positive and negative zero, this approach is commonly used to represent numbers in floating point. Unlike the binary representation discussed in Section 1.3, floating point representations allow the binary point to move (or float) in order to take maximum advantage of the available bits. Floating point representation is beyond the scope of this text, but students interested in the subject may refer to the IEEE 754 floating point standard for additional information. A second way to represent negative numbers that is far more prevalent for integers and fixed point numbers is called Two’s Complement Representation , or simply Two’s Complement. The reason for this popularity will become clear when we discuss addition and subtraction in Chapter 5. Two’s complement is very much like binary, so much in fact that there is no notation to distinguish the two. It is always necessary to know from context whether a sequence of bits (or hexadecimal digits) represents a binary or two’s complement number. Two’s complement differs from binary in two ways. First, the number of bits used to represent a number is fixed beforehand. Second, the weight of the most significant bit is negative. To be precise, if an m - bit two’s complement number ( Bm- 1B 1 B 0 ) is used to represent an integer, N , then the value of N can be evaluated using the expansion: N = – Bm - 1 x 2 m -^1 + … + B 1 x 21 + B 0 x 20 ( 2. 5 ) Extending Equation 1.5 to include fractional bits is straightforward and is left as an exercise for the student. Example 2 .8: Convert the 8-bit two’s complement number 10010011 2 to decimal. Solution: Using equation 1.5, 100100112 expands to: 100100112 = – 1 x 27 + 1 x 24 + 1 x 21 + 1 x 20 = – 128 + 16 + 2 + 1 = - 109 The technique of writing weights above each bit and summing (See Example 2 .3) may also be used for two’s complement numbers provided (a) all m bits are shown and (b) the weight of the leftmost bit is negated.

Example 2 .1 1. Convert 2056 into 12-bit two’s complement form. Solution: 2 m -^1 = 2048, so the valid range of integers is (–2048…2047). 2056 falls outside of this range so conversion is not possible. Example 2.12 Convert 108 to 8-bit two’s complement. Solution: 2 m -^1 = 128, so the valid range of integers is (–128…127). 108 is within this range so conversion is possible. The number is not negative so we write down 0 for the sign bit. Divide by 2 seven times, keeping the remainder each time: 108 ÷ 2 = 54 remainder 0 ÷ 2 = 27 remainder 0 ÷ 2 = 13 remainder 1 ÷ 2 = 6 remainder 1 ÷ 2 = 3 remainder 0 ÷ 2 = 1 remainder 1 ÷ 2 = 0 remainder 1 Write down the remainder in reverse order to the right of the 0 (sign bit) we wrote earlier: (^011011002) If we wish to add a binary point to the two’s complement representation so that there are n fractional bits, conversion from decimal becomes a little more involved. The easiest approach is to first multiply the decimal number by 2 n^ and then proceed as if it were an integer. After the integer conversion is complete, divide the result by 2 n^ by moving the binary point to the left n bits. Example 2.13. Convert 12.38 to an 8-bit two’s complement number with 3 bits of fraction. Solution: First multiply – 12.38 by 2^3 = – 99.04. Next, convert – 99 to 8-bit two’s complement:

  • 99 → (^010111012) Finally, move the binary point left 3 bits. 0 1011.101 2 Two’s Complement numbers may also be represented in hexadecimal. The conversion to hexadecimal starts the same as it does for binary: Group bits four at a time starting with the binary point, then pad the rightmost group with zeros if it contains less than four bits. The difference is that if the leftmost group has less than four bits, pad it with copies of the sign bit instead of zeros. Finally, convert each group to a hexadecimal digit as before.

Example 2.14. Represent the following 10-bit two’s complement numbers in hexadecimal: (a) 1001011011 2 (b) 0110001. 1102 Solution: Group bits, pad if necessary and convert: 10010110112 → 1110 0101 1011 → E5B 16 0110001.110 2 → 0011 0001.1100 → 31.C 16 The technique of duplicating the sign bit is called sign extension. It provides a way to increase the number of bits used to represent a two’s complement number without changing the number itself. Example 2.15. Convert the 9-bit two’s complement numbers 1011.10101 2 and 0110100112 into 12 - bit two’s complement numbers. Solution: duplicate the sign bit 12-9 = 3 times: 1011.10101 2 → 1111011.10101 2 0110100112 → (^0000110100112)

Exercises

  1. Convert the following binary numbers to decimal. (a) 11011 (c) 10110010 (e) 100101101101 (b) 1.0110 (d) 11101.011 (f) 1 100111 101.
  2. Convert the following decimal numbers to binary. If the fractional part does not terminate, give four (4) bits of precision. (a) 49 (c) 185 (e) 2943 (b) 6.125 (d) 15.82 (f) 361.
  3. Convert the binary numbers in problem 4 to hexadecimal.
  4. Convert the following hexadecimal numbers to binary. (a) FE (c) A57 (e) 1FFF (b) 7.A (d) 19.8 (f) 13B.D
  5. Convert the hexadecimal numbers in Problem 7 to decimal, first by using Equation 1-2 then by converting your (binary) answers from Problem 7.
  6. Extend Equation 1.5 to include n fractional bits. The total number of bits remains m.
  7. Convert the following 8 - bit two’s complement numbers to decimal. (a) 01100101 (c) 11111111 (e) 01101101 (b) 1 10 .0 1100 (d) 010110 .0 1 (f) 111101.
  8. Convert the following decimal numbers to 8 - bit two’s complement. Assume no fractional bits. If a number cannot be represented, explain why it cannot. (a) 97 (c) – 128 (e) – 3 (b) – 100 (d) 128 (f) 56