1 digital logic design lecture 2 more number systems/complements

Download 1 Digital Logic Design Lecture 2 More Number Systems/Complements

If you can't read please download the document

Upload: alban-walters

Post on 18-Jan-2018

257 views

Category:

Documents


14 download

DESCRIPTION

3 Understanding Binary Numbers °Binary numbers are made of binary digits (bits): 0 and 1 °How many items does an binary number represent? (1011) 2 = 1x x x x2 0 = (11) 10 °What about fractions? (110.10) 2 = 1x x x x x2 -2 °Groups of eight bits are called a byte ( ) 2 °Groups of four bits are called a nibble. (1101) 2

TRANSCRIPT

1 Digital Logic Design Lecture 2 More Number Systems/Complements 2 Overview Hexadecimal numbers Related to binary and octal numbers Conversion between hexadecimal, octal and binary Value ranges of numbers Representing positive and negative numbers Creating the complement of a number Make a positive number negative (and vice versa) Why binary? 3 Understanding Binary Numbers Binary numbers are made of binary digits (bits): 0 and 1 How many items does an binary number represent? (1011) 2 = 1x x x x2 0 = (11) 10 What about fractions? (110.10) 2 = 1x x x x x2 -2 Groups of eight bits are called a byte ( ) 2 Groups of four bits are called a nibble. (1101) 2 4 Understanding Hexadecimal Numbers Hexadecimal numbers are made of 16 digits: (0,1,2,3,4,5,6,7,8,9,A, B, C, D, E, F) How many items does an hex number represent? (3A9F) 16 = 3x x x x16 0 = What about fractions? (2D3.5) 16 = 2x x x x16 -1 = Note that each hexadecimal digit can be represented with four bits. (1110) 2 = (E) 16 Groups of four bits are called a nibble. (1110) 2 5 Putting It All Together Binary, octal, and hexadecimal similar Easy to build circuits to operate on these representations Possible to convert between the three formats 6 Converting Between Base 16 and Base 2 Conversion is easy! Determine 4-bit value for each hex digit Note that there are 2 4 = 16 different values of four bits Easier to read and write in hexadecimal. Representations are equivalent! 3A9F 16 = A9F 7 Converting Between Base 16 and Base 8 1.Convert from Base 16 to Base 2 2.Regroup bits into groups of three starting from right 3.Ignore leading zeros 4.Each group of three bits forms an octal digit = A9F 16 = A9F 8 9 Decimal 2 Binary 10 Octal Numbers: [Base 8],[ 0,1,3,4,5,6,7] Octal to Decimal Conversion: Example:- [2374] 8 = [ ? ] 10 =48 0 +78 1 +38 2 +28 3 =[1276] 10 Number systems () Number systems (Octal Numbers) Octal number has base 8 Each digit is a number from 0 to 7 Each digit represents 3 binary bits Was used in early computing, but was replaced by hexadecimal 11 Decimal to Octal Conversion: The Division: [359] 10 = [ ? ] 8 By using the division system: Reminder Number systems () Number systems (Octal Numbers) Quotient 12 Binary to Octal Conversion: Example:- [110101] 2 = [ ? ] 8 Here we will take 3 bits and convert it from binary to decimal by using the decimal to binary truth table: BinaryDecimal = (65) 8 { 65 { Number systems () Number systems (Octal Numbers) 13 Octal to Binary Conversion: Example:- [13] 8 = [ ? ] 2 Here we will convert each decimal digit from decimal to binary (3 bits) using the decimal to binary truth table: BinaryDecimal (13) 8 = (001011) 2 Number systems () Number systems (Octal Numbers) 14 Radix Based Conversion (Example) Convert 1234 decimal into octal Radix 8Answer Divide by radix 15 Octals Converting to decimal from octal: Evaluate the power series Example *8 1 2* *8 0 + = 16 Hexadecimal Hexadecimal is used to simplify dealing with large binary values: Base-16, or Hexadecimal, has 16 characters: 0-9, A-F Represent a 4-bit binary value: (0) to (F) Easier than using ones and zeros for large binary values Commonly used in computer applications Examples: = = C = A6 C2 16 Hex values can be followed by an H to indicate base-16. Example: A6 C2 H 17 Hex Values in Computers 18 Decimal to Hexadecimal DecimalHex A 11B 12C 13D 14E 15F 19 Conversion Binary to Hexadecimal = = = = 6 AC16 20 Radix Based Conversion (Example) Convert 1234 decimal into hexadecimal Radix 16Answer 4D2 16 Divide by radix D 21 Hexadecimals Base 16 Converting to decimal from hex: Evaluate the power series Example 2 E A *16 1 2* * = 22 Octal to Hex Conversion To convert between the Octal and Hexadecimal numbering systems Convert from one system to binary first Then convert from binary to the new numbering system 23 Hex to Octal Conversion Ex : Convert E8A 16 to octal First convert the hex to binary: and re-group by 3 bits (starting on the right) Then convert the binary to octal: So E8A 16 = 24 Octal to Hex Conversion Ex : Convert to hex First convert the octal to binary: re-group by 4 bits (add leading zeros) Then convert the binary to hex: 1 E A So = 1EA 16 25 Octal to Hexadecimal Hexadecimal DecimalOctal Binary 26 Octal to Hexadecimal Technique Use binary as an intermediary 27 Example = ? E = 23E 16 28 Hexadecimal to Octal Hexadecimal DecimalOctal Binary 29 Hexadecimal to Octal Technique Use binary as an intermediary 30 Example 1F0C 16 = ? 8 1 F 0 C F0C 16 = 31 Example: Hex Octal Example: Convert the hexadecimal number 5A H into its octal equivalent. 5A H = A = Solution: First convert the hexadecimal number into its decimal equivalent, then convert the decimal number into its octal equivalent. 32 Fractions (Example) 33 Fractions (Example) 34 Radix Based Conversion (Example) Convert decimal into binary Radix 2 Answer FractionRadixTotal (Fraction x Radix)IntegerFraction Multiply by radix 2 35 FractionRadix Total (Fraction x Radix)IntegerFraction Radix Based Conversion (Example) Convert to base 16 (up to 4 fractional point) Radix 16 Answer Multiply by radix 16 36 37 How To Represent Signed Numbers Plus and minus sign used for decimal numbers: 25 (or +25), -16, etc..For computers, desirable to represent everything as bits. Three types of signed binary number representations: signed magnitude, 1s complement, 2s complement. In each case: left-most bit indicates sign: positive (0) or negative (1). Consider signed magnitude: = Sign bitMagnitude = Sign bitMagnitude 38 Complement It has already been studied that subtracting one number from another is the same as making one number negative and just adding them. We know how to create negative numbers in the binary number system. How to perform 2s complement process. How the 2s complement process can be use to add (and subtract) binary numbers. Digital electronics requires frequent addition and subtraction of numbers. You know how to design an adder, but what about a subtracter? A subtracter is not needed with the 2s complement process. The 2s complement process allows you to easily convert a positive number into its negative equivalent. Since subtracting one number from another is the same as making one number negative and adding, the need for a subtracter circuit has been eliminated. 39 3-Digit Decimal A bicycle odometer with only three digits is an example of a fixed-length decimal number system. The problem is that without a negative sign, you cannot tell a +998 from a -2 (also a 998). Did you ride forward for 998 miles or backward for 2 miles? Note: Car odometers do not work this way forward (+) backward (-) 40 Negative Decimal How do we represent negative numbers in this 3-digit decimal number system without using a sign? Cut the number system in half. Use 001 499 to indicate positive numbers. Use 500 999 to indicate negative numbers. Notice that 000 is not positive or negative pos(+) neg(-) 41 3-Digit Decimal (Examples) (-5) + 2 (-3) (-3) 3 (-2) + (-3) (-5) 003 Disregard Overflow 995 Disregard Overflow It Works! 42 Complex Problem The previous examples demonstrate that this process works, but how do we easily convert a number into its negative equivalent? In the examples, converting the negative numbers into the 3-digit decimal number system was fairly easy. To convert the (-3), you simply counted backward from 1000 (i.e., 999, 998, 997). This process is not as easy for large numbers (e.g., -214 is 786). How did we determine this? To convert a large negative number, you can use the 10s Complement Process. 43 Complement The 10s Complement process uses base-10 (decimal) numbers. Later, when were working with base-2 (binary) numbers, you will see that the 2s Complement process works in the same way. First, complement all of the digits in a number. A digits complement is the number you add to the digit to make it equal to the largest digit in the base (i.e., 9 for decimal). The complement of 0 is 9, 1 is 8, 2 is 7, etc. Second, add 1. Without this step, our number system would have two zeroes (+0 & -0), which no number system has. 44 10s Complement Examples 785 Example #1 Example #2 Complement DigitsAdd 1Complement DigitsAdd 1 786 45 Ones Complement Representation The ones complement of a binary number involves inverting all bits. 1s comp of is s comp of is For an n bit number N the 1s complement is (2 n -1) N. Called diminished radix complement by Mano since 1s complement for base (radix 2). To find negative of 1s complement number take the 1s complement = Sign bitMagnitude = Sign bitMagnitude 46 Twos Complement Representation The twos complement of a binary number involves inverting all bits and adding 1. 2s comp of is s comp of is For an n bit number N the 2s complement is (2 n -1) N + 1. Called radix complement by Mano since 2s complement for base (radix 2). To find negative of 2s complement number take the 2s complement = Sign bitMagnitude = Sign bitMagnitude 47 Twos Complement Shortcuts Algorithm 1 Simply complement each bit and then add 1 to the result. Finding the 2s complement of ( ) 2 and of its 2s complement N = [N] = Algorithm 2 Starting with the least significant bit, copy all of the bits up to and including the first 1 bit and then complementing the remaining bits. N = [N] = 48 Finite Number Representation Machines that use 2s complement arithmetic can represent integers in the range -2 n-1