Notes - Chapter 2

Notes - Chapter 2

DEPARTMENT OF ELECTRICAL AND COMPUTER ENGINEERING, THE UNIVERSITY OF NEW MEXICO ECE-238L: Computer Logic Design Fall 2013 Notes - Chapter 2 BINARY NUMBER CONVERSIONS DECIMAL NUMBER SYSTEM DIGIT . A decimal digit can take values from 0 to 9: 0 1 2 3 4 5 6 7 8 9 . Digit-by-digit representation of a positive integer number (powers of 10): Number: 9372 hundreds tens thousands units 9 3 7 2 9 thousands, 3 hundreds, 7 tens, and 2 units 103 102 101 100 9372 = 9×103 + 3×102 + 7×101 + 2×100 Positional Number Representation . Let’s consider the numbers from 0 to 999. We represent these numbers with 3 digits (each digit being a number between 0 and 9). We show a 3-digit number using the positional number representation: MATHEMATICAL REPRESENTATION EXAMPLE 3-digit d2 d1 d0 2 0 9 Third Digit Second Digit First Digit Third Digit Second Digit First Digit . The positional number representation allows us to express the decimal value using powers of ten: 2 1 0 퐷 = 푑2 × 10 + 푑1 × 10 + 푑0 × 10 . Example: 3-digit representation Decimal Powers of 10: 2 1 0 Number d2d1d0 d2 10 + d1 10 + d0 10 2 1 0 0 000 0 10 + 0 10 + 0 10 9 009 0 102 + 0 101 + 9 100 11 011 0 102 + 1 101 + 1 100 25 025 0 102 + 2 101 + 5 100 90 090 0 102 + 9 101 + 0 100 1 102 + 2 101 + 8 100 128 128 2 1 0 255 255 2 10 + 5 10 + 5 10 Exercise: Write down the 3-digit and the powers of ten representations for the following numbers: 2 1 0 Decimal Number 3-digit representation 푑2 × 10 + 푑1 × 10 + 푑0 × 10 5 254 100 99 Instructor: Daniel Llamocca DEPARTMENT OF ELECTRICAL AND COMPUTER ENGINEERING, THE UNIVERSITY OF NEW MEXICO ECE-238L: Computer Logic Design Fall 2013 General Case: . Positional number representation for an integer positive number with ‘n’ digits: dn-1dn-2 ... d1d0 n-1 n-2 1 0 Decimal Value: dn-1 10 + dn-2 10 + ... + d1 10 + d0 10 . Example: 1098324 (7 digits). 1098324 1106 0 105 9 104 8 103 3102 2 101 4 100 203476 (6 digits). 203476 2 105 0 104 3103 4 102 7 101 6 100 Maximum value: . The table presents the maximum attainable value for a given number of digits. What pattern do you find? Can you complete it for the highlighted cases (4 and 6)? Number of digits Maximum value Range 1 9 = 101-1 0 9 0 101-1 2 99 = 102-1 0 99 0 102-1 3 999 = 103-1 0 999 0 103-1 4 5 99999 = 105-1 0 99999 0 105-1 6 … n 999…999 = 10n-1 0 999…999 0 10n-1 . Maximum value for a number with ‘n’ digits: Based on the table, the maximum decimal value for a number with ‘n’ digits is given by: n-1 n-2 1 0 n D = 999...999 = 9 10 + 9 10 + ... + 9 10 + 9 10 = 10 -1 n digits With ‘n’ digits, we can represent positive integer numbers from 0 to 10n-1. With 7 digits, what is the range (starting from 0) of positive numbers that we can represent? How many different numbers can we represent? BINARY NUMBER SYSTEM . We are used to the decimal number system. However, DIGIT BIT there exist other number systems: octal, hexadecimal, vigesimal, binary, etc. In particular, binary numbers are 0 1 2 3 4 5 6 7 8 9 0 1 very practical as they are used by digital computers. For binary numbers, the counterpart of digit (that can take values from 0 to 9) is the bit (binary digit) that can take the value of 0 or 1. Bit: Unit of information that a computer uses to process and retrieve data. It can also be used as a logical variable (see Chapter 1). Binary representation: We use the positional number representation. Note that here, we are using a string of bits to represent a binary number. Converting a binary number into a decimal number: The following figure depicts two cases: 2-bit numbers and 3-bit numbers. Note that the positional representation with powers of two let us obtain the decimal value (integer positive) of the binary number. Instructor: Daniel Llamocca DEPARTMENT OF ELECTRICAL AND COMPUTER ENGINEERING, THE UNIVERSITY OF NEW MEXICO ECE-238L: Computer Logic Design Fall 2013 Binary number Powers of 2: Decimal 1 0 b1b0 b1 2 + b0 2 Number MATHEMATICAL REPRESENTATION 2-bit 1 0 b b 00 0 2 + 0 2 0 1 0 1 0 01 0 2 + 1 2 1 10 1 21 + 0 20 2 Second Bit First Bit 11 1 21 + 1 20 3 Binary number Powers of 2: Decimal 2 1 0 b2b1b0 b2 2 + b1 2 + b0 2 Number 2 1 0 MATHEMATICAL REPRESENTATION 000 0 2 + 0 2 + 0 2 0 2 1 0 3-bit 001 0 2 + 0 2 + 1 2 1 b b b 010 0 22 + 1 21 + 0 20 2 2 1 0 011 0 22 + 1 21 + 1 20 3 100 1 22 + 0 21 + 0 20 4 2 1 0 Third Bit Second Bit First Bit 101 1 2 + 0 2 + 1 2 5 110 1 22 + 1 21 + 0 20 6 111 1 22 + 1 21 + 1 20 7 General case: . Positional number representation for a binary number with ‘n’ bits: b b ... b b n-1 n-2 1 0 Most significant Least significant (leftmost) bit (rightmost) bit This formula converts a binary number into a decimal number: Decimal Value (integer positive): n-1 n-2 1 0 D = bn-1 2 + bn-2 2 + ... + b1 2 + b0 2 . To avoid confusion, we usually write a binary number and attach a suffix ‘2’: (푏푛−1푏푛−2 … 푏1푏0)2 5 4 3 2 1 0 . Example: 6 푏푖푡푠: (101011)2 ≡ 퐷 = 1 × 2 + 0 × 2 + 1 × 2 + 0 × 2 + 1 × 2 + 1 × 2 = 43 3 2 1 0 4 푏푖푡푠: (1011)2 ≡ 퐷 = 1 × 2 + 0 × 2 + 1 × 2 + 1 × 2 = 11 . Maximum value for a given number of bits. Complete the tables for the highlighted cases (4 and 6): Number of bits Maximum value Range 1 1 1 12 2 -1 0 12 0 2 -1 2 2 2 112 2 -1 0 112 0 2 -1 3 3 3 1112 2 -1 0 1112 0 2 -1 4 5 5 5 111112 2 -1 0 111112 0 2 -1 6 … n n n 111…1112 2 -1 0 111…1112 0 2 -1 . Maximum value for ‘n’ bits: The maximum decimal value with ‘n’ bits is given by: n-1 n-2 1 0 n D = 111...111 = 1 2 + 1 2 + ... + 1 2 + 1 2 = 2 -1 n bits With ‘n’ bits, we can represent positive integer numbers from 0 to 2n-1. (2n numbers) Instructor: Daniel Llamocca DEPARTMENT OF ELECTRICAL AND COMPUTER ENGINEERING, THE UNIVERSITY OF NEW MEXICO ECE-238L: Computer Logic Design Fall 2013 . The case n=8 bits is of particular interest, as a string of 8 bits is called a byte. Here, the range for 8-bit numbers is 0 to 28-1 0 to 255. b b b b b b b b 7 6 5 4 3 2 1 0 Most significant Least significant (leftmost) bit (rightmost) bit . The table shows some examples: Decimal 8-bit format b 27 + b 26 + b 25 + b 24 + b 23 + b 22 + b 21 + b 20 Number b7b6b5b4b3b2d1d0 7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0 0 00000000 0 2 + 0 2 + 0 2 + 0 2 + 0 2 + 0 2 + 0 2 + 0 2 9 00001001 0 27 + 0 26 + 0 25 + 0 24 + 1 23 + 0 22 + 0 21 + 1 20 11 00001011 0 27 + 0 26 + 0 25 + 0 24 + 1 23 + 0 22 + 1 21 + 1 20 25 00011001 0 27 + 0 26 + 0 25 + 1 24 + 1 23 + 0 22 + 0 21 + 1 20 90 01011010 0 27 + 1 26 + 0 25 + 1 24 + 1 23 + 0 22 + 1 21 + 0 20 128 10000000 1 27 + 0 26 + 0 25 + 0 24 + 0 23 + 0 22 + 0 21 + 0 20 255 11111111 1 27 + 1 26 + 1 25 + 1 24 + 1 23 + 1 22 + 1 21 + 1 20 Exercise: Convert the following binary numbers (positive integers) to their decimal values: 8-bit Decimal 7 6 5 4 3 2 1 0 representation 푏7 × 2 + 푏6 × 2 + 푏5 × 2 + 푏4 × 2 + 푏3 × 2 + 푏2 × 2 + 푏1 × 2 + 푏0 × 2 Number 00000001 00001001 10000101 10000111 11110011 . In general to convert a number of base 'r' (r = 2, 3,4 ,…) to decimal, we use the following formula: Number in base 'r': (푟푛−1푟푛−2 … 푟1푟0)푟 푛−1 푛−2 1 0 Conversion to decimal: 퐷 = 푟푛−1 × 푟 + 푟푛−2 × 푟 + ⋯ + 푟1 × 푟 + 푟0 × 푟 Also, the maximum decimal value for a number in base 'r' with 'n' digits is: 푛−1 푛−2 1 0 푛 퐷 = 푟푟푟 … 푟푟푟 = 푟 × 푟 + 푟푛−2 × 푟 + ⋯ + 푟 × 푟 + 푟 × 푟 = 푟 − 1 Example: Base-8: Number of digits Maximum value Range 1 1 1 78 8 -1 0 78 0 8 -1 2 2 2 778 8 -1 0 778 0 8 -1 3 3 3 7778 8 -1 0 7778 0 8 -1 … n n n 777…7778 8 -1 0 777…7778 0 8 -1 Examples: . (50632)8: Number in base 8 (octal system) Number of digits: n = 5 Conversion to decimal: 퐷 = 5 × 84 + 0 × 83 + 6 × 82 + 3 × 81 + 2 × 80 = 20890 .

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    22 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us