Binary Number Systems

Binary Number Systems
Slide Note
Embed
Share

Learn about the symbolic representation, digit values, conversion methods, and extending polynomial evaluation to numbers with a fractional part in binary number systems. Understand the process of converting from any radix to decimal using polynomial evaluation with practical examples. Explore the concept of positional weights and numeric interpretation in polynomial evaluation for better understanding.

  • Binary Number Systems
  • Polynomial Evaluation
  • Conversion Methods
  • Positional Weights
  • Numeric Interpretation

Uploaded on Feb 20, 2025 | 0 Views


Download Presentation

Please find below an Image/Link to download the presentation.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

You are allowed to download the files provided on this website for personal or commercial use, subject to the condition that they are used lawfully. All files are the property of their respective owners.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.

E N D

Presentation Transcript


  1. Chapter 2 Binary Number Systems Part 1: Polynomial Evaluation

  2. Symbols and their values used in positional number systems Digit Symbols Corresponding Digit Values System Radix Binary 2 0,1 0,1 0,1,2,3,4, 5,6,7,8,9 0,1,2,3,4, 5,6,7,8,9 Decimal 10 0,1,2,3,4,5,6,7, 8,9,A,B,C,D,E,F 0,1,2,3,4,5,6,7, 8,9,10,11,12,13,14,15 Hex 16

  3. POLYNOMIAL EVALUATION Representation: ?? ? ???? where: ??are the digit symbols Ex: 365210 Subscript used to identify radix These are the digit symbols Interpretation: ?? ??? ?+ + ????+ ???? where: ??are the corresponding digit values and: ? is the radix (number base) Ex: 3 103+ 6 102+ 5 101+ 2 100

  4. POLYNOMIAL EVALUATION Symbolic representation (What we write) Digit values (coefficients) 5 102 + 4 101 + 7 100 547 10 Positional weights (powers of the radix) Subscript used to indicate the radix (number base) = 500 + 40 + 7 = 547 The result of polynomial evaluation is always a decimal number, regardless of the radix used in the original representation. Numeric interpretation (What we understand)

  5. Converting from ANY Radix to Decimal Example: Converting from Radix 5 to Decimal 31245 = 3 53 + 1 52 + 2 51 + 4 50 = 3 125 + 1 25 + 2 5 + 4 1 = 375 + 25 + 10 + 4 = 41410 NOTE: Polynomial evaluation may be used to convert from ANY radix to decimal. The positional weights simply become powers of the radix.

  6. CONVERT BINARY TO DECIMAL (Using Polynomial Evaluation) 10112 = 1 23 + 0 22 + 1 21 + 1 20 = 1 8 + 1 2 + 1 1 = 8 + 2 + 1 = 1110

  7. EXTENDING POLYNOMIAL EVALUATION TO NUMBERS WITH A FRACTIONAL PART 10.0101112 = 1 21 + 0 20 + 0 2-1 + 1 2-2 + 0 2-3 + 1 2-4 + 1 2-5 + 1 2-6 = 1 21 + 1 2-2 + 1 2-4 + 1 2-5 + 1 2-6 = 2 + 1/4 + 1/16 + 1/32 + 1/64 = 2 + 0.25 + 0.0625 + 0.03125 + 0.015625 = 2.35937510 Tedious! Four divisions and long decimal fractions!

  8. AN EASIER METHOD = 100101112 / 26 10.0101112 6 fractional digits = (1 27 + 0 26 + 0 25 + 1 24 + 0 23 + 1 22 + 1 21 + 1 20)/26 = (128 + 16 + 4 + 2 + 1)/64 = 151/64 = 2.35937510 Only a single division!

  9. Converting Fractions Sometimes a fractional value has a finite representation in one number base, but not in another: 1 3 =.13= .333333333333 10 1 10 =.110= .0001100110011 2 This happens for the reduced fraction k/N iff there is any prime factor P of N such that the destination radix is not divisible by P.

  10. Representation Error Computers store numbers using a fixed number of digits (aka, fixed precision ) Some values may not have a finite representation in binary (e.g., 1 10) Limiting the number of digits introduces a representation error: 1 10 = .110 .000110012 (8 bits) = .0976562510

  11. Calculating Representation Error Consider the representation of one tenth from the previous slide, using 8 fractional bits: Desired value Value Represented 1 10 000110012 Absolute Error = 28 1 10 25 256 = 1 256 25 10 10 256 6 = = 2560 = 0.0023437510 % Relative Error =100 ???????? ????? ??????? ?????= 100 0.00234375 =2.34% 0.1

  12. Chapter 2 Binary Number Systems Part 2: Unsigned Decimal to Binary Conversion

  13. UNSIGNED DECIMAL TO BINARY CONVERSION Method 1: Separate problem into two parts: Integer Part: Use repeated division Fractional Part: Use repeated multiplication Method 2: Decompose the decimal number into a corresponding sum of powers of 2.

  14. REPEATED DIVISION Consider what happens when you repeatedly divide a decimal integer by 10: 123/10 Quotient = 12, Remainder = 3 (1 s digit) 12/10 Quotient = 1, Remainder = 2 (10 s digit) 1/10 Quotient = 0, Remainder = 1 (100 s digit) Note: 1. 0 Remainder 9 (a single decimal digit) 2. Digits are produced in Right-to-Left order

  15. UNSIGNED DECIMAL TO BINARY Method 1: Integer Part (Repeated Division) N 13 6 3 1 N 2 6 3 1 0 Remainder 1 0 1 1 STOP Result 1. Digits are produced right-to-left starting from the radix point. 01. 101. 1101. NOTE: Repeated division may be used to convert from decimal to ANY radix. Simply divide by the radix.

  16. REPEATED MULTIPLICATION Consider what happens when you repeatedly multiply a decimal fraction by 10: 10 .123 = 1.23 10 .23 = 2.3 10 .3 = 3 Whole Part = 1, Fractional Part = .23 Whole Part = 2, Fractional Part = .3 Whole Part = 3, Fractional Part = .0 Note: 1. 0 Whole Part 9 (a single decimal digit) 2. Digits are produced in Left-to-Right order

  17. UNSIGNED DECIMAL TO BINARY Method 1: Fractional Part (Repeated Multiplication) Product (2 N) 0.2 0.4 0.8 1.6 1.2 Whole Fractional Part 0 0 0 1 1 N .1 .2 .4 .8 .6 Part .2 .4 .8 .6 .2 Result .0 .00 .000 .0001 .00011 Digits are produced left-to-right starting from the radix point. Begins to repeat! NOTE: Repeated multiplication may be used to convert from decimal to ANY radix. Simply multiply by the radix.

  18. UNSIGNED DECIMAL TO BINARY Method 2: Decomposition Convert 75.310 to Binary: 2k k 6 64 Whole Part: 5 32 75 = 64 + 8 + 2 + 1 4 16 3 8 = 10010112 2 4 1 2 Fractional Part (approximation): .3 = .25 + .0625 0 1 -1 .5 -2 .25 = .01012 -3 .125 -4 .0625

  19. Chapter 2 Binary Number Systems Part 3: Number Representations that use a Fixed Number of Digits

  20. Resolution, Precision, Accuracy Resolution: Refers to how finely we can represent a value usually determined by the number of digits in the representation. Precision: Refers to the reproducibility of a measurement i.e., how many digits remain the same every time you measure the same value. Accuracy: Refers to the correctness of a measurement.

  21. INFINITE PRECISION Placing an infinite number of values on the number line requires a representation that imposes no limit on the number of digits. Incrementing any number always moves to the right, producing a result that is always one greater than the previous.

  22. THE EFFECT OF FIXED PRECISION (Using a number circle instead of a line) Fixed Precision = Labels inside the circle are symbolic representations. max min Fixed # of digits Wrap Around Finite # of values min and max limits Overflow: Occurs when an arithmetic result is beyond the min or max limits. Labels outside the circle are the corresponding numeric interpretations.

  23. TWOS COMPLEMENT REPRESENTATION OF SIGNED BINARY INTEGERS There are several possible ways to represent signed binary numbers. Wrap Around Two s complement is the most common. Most-Significant Bit: 0 if positive, 1 if negative. Negative Values: Not simply a 1 followed by magnitude bits. max min Overflow: No longer occurs between 0000 and 1111.

  24. Chapter 2 Binary Number Systems Part 4: Signed Number Conversions

  25. Changing the Sign of a Twos Complement Number (Method 1) If +1.2510 = 0001.01002 Then -1.2510 = ????.????2 1. Change every bit: 0001.0100 Simply changing the most- significant bit is NOT the same and doesn t work! . . . 1110.1011 2. Then add 1 to the least-significant1110.1100 bit position. +1 Consider what happens when the starting value is a full-scale negative value, such as -12810 = 100000002

  26. Changing the Sign of a Twos Complement Number (Method 2) If +1.2510 = 0001.01002 Then -1.2510 = ????.????2 Copy right-to-left through first 1: Copy opposite of all remaining bits: 0001.0100 . . . . . . 1110.1 100

  27. CONVERTING SIGNED DECIMAL TO TWO S COMPLEMENT Positive values: 1. Convert as if unsigned 2. Zero extend (add 0 s on the left) to fill out the representation to the desired number of bits Note: Most-significant bit must be 0 Negative values: 1. Find corresponding positive representation as above 2. Find the "2 s complement" of the result.

  28. CONVERTING SIGNED DECIMAL TO TWO S COMPLEMENT Example: Find the 8-bit2 s complement representation of -2510 1. Convert the magnitude to unsigned binary: 2510 = 16 + 8 + 1 110012 2. Zero extend to 8 bits: 11001 00011001 3. Find the 2 s complement: 00011001 111001112

  29. CONVERTING TWOS COMPLEMENT TO SIGNED DECIMAL Method 1: Positive values (most-significant bit is 0) Same as unsigned (use polynomial evaluation) Negative values (most-significant bit is 1) 1. Use Two s Complement procedure to find the representation of the corresponding positive value. 2. Find decimal magnitude using polynomial evaluation 3. Add a leading minus sign

  30. Converting Twos Complement to Signed Decimal (Method 1) Original 2 s complement number: 1. Negative find positive equivalent: 2. Polynomial evaluation: 3. Add a leading minus sign: 100011002 011101002 64+32+16+4 = 11610 11610

  31. CONVERTING TWOS COMPLEMENT TO SIGNED DECIMAL Method 2: Use polynomial evaluation, but make the weight of the most-significant bit position negative.

  32. Converting Twos Complement to Signed Decimal (Method 2) Original 2 s complement number: 100011002 Polynomial evaluation: 128+8+4 = 11610

  33. Extending Representation Width Unsigned - Just add leading zeroes: 000000112= 310 000000112= 310 2 s Complement Signed: If positive, add leading zeroes: 00000112= +310 000000112= +310 If negative, add leading ones: 000011012= 310 111111012= 310 Zero-Extending Sign-Extending

  34. Chapter 2 Binary Number Systems Part 5: Worked Examples

  35. Convert unsigned 256 to decimal Base R to Decimal polynomial evaluation: 256 = 2x61 + 5x60 = 2x6 + 5x1 = 12 + 5 = 1710

  36. Convert unsigned 2510 to base 7 Whole #10 to Base R repeated division (by 7): 25 7 Q=3, R=4 47 3 2 Q=0, R=3 3 7 347 STOP

  37. Convert unsigned .310 to base 7 Fractional #10 to Base R repeated multiplication: 7 x .3 = 2.1 7 x .1 = 0.7 7 x .7 = 4.9 7 x .9 = 6.3 .2 .20 .204 .2046 .20462046 Repeats!

  38. Converting -25.7510to 2s Comp. -25: 25 = 16 + 8 + 1 011001 -25 = 100111 Correct Method: +25.75 = 16 + 8 + 1 + .5 + .25 = 011001.112 Find the negative representation: 100110.01 Check: 100110.01 = 10011001/22 .75: .75 = .5 + .25 .11 Combining results: 100111.112 = (-128+16+8+1)/4 = -103/4 = -25.7510 Checking (poly eval): = -24.2510

  39. Convert -75.7510to 2s complement 1st: Get Binary Magnitude 2nd: Convert to 2 s Complement 7510 = 64 + 8 + 2 + 1 = 26 + 23 + 21 + 20 = 10010112 +75.7510 = 01001011.112 Make sure the most- significant bit is 0. Find 75.7510: 2 s Comp: 10110100.01 .7510 = .5 + .25 = 2-1 + 2-2 = .112 The most-significant bit must be 1 (negative), so the minimum number of bits is 10. 75.7510 = 1001011.112

  40. Convert 2s Comp. 1001.01102 to decimal Method #1 Method #2 1001.0110 (< 0) - Find pos. equiv: Use poly. eval. w/neg. 1st term: 1001.0110: 2 s Comp: 0110.1010 = -8 + 1 + .25 + .125 = -7 + .375 = -6.62510 Get decimal = 4+2+.5+.125 = 6.62510 Add minus sign -6.62510

  41. Chapter 2 Binary Number Systems Part 6: Power Relationships

  42. MOTIVATION Hexadecimal is a convenient short-hand for binary: Hex (radix 16) numbers require 1/4th as many digits than their equivalent binary (radix 2) representation Easier for humans reduces transcription errors Conversion is trivial due to power relationship (16 = 24): Each hex digit corresponds to a group of 4 binary digits. Easy to convert: Groups are independent of each other.

  43. Hex/Binary Table

  44. Example: Hex to Binary Hex Binary 0 0000 1 0001 2 0010 Convert F1.2C16 to Binary: 3 0011 4 0100 5 0101 F 1 . 2 C 6 0110 7 0111 8 1000 9 1001 1111 0001 . 0010 11002 A 1010 1011 B C 1100 D 1101 E 1110 F 1111

  45. Example: Binary to Hex Hex Binary Original binary number: 1011010.10010112 0 0000 1 0001 2 0010 1. Split into groups of 4, starting at radix point: 101 1010 . 1001 011 Form groups working outward from the radix point! 3 0011 4 0100 5 0101 6 0110 7 0111 2. Pad with 0 s to complete the groups: 0101 1010 . 1001 0110 8 1000 9 1001 A 1010 1011 B 3. Replace each group by equivalent hex digit: 5 A . 9 616 C 1100 D 1101 E 1110 F 1111

  46. Example: 110101.0101012 to Hex Use power relationship (16 = 24) Form groups of 4 bits, starting at radix point: 0011 0101 . 0101 0100 0011 0101 . 0101 0100 Hex Binary Hex Binary 0 0000 8 1000 1 0001 9 1001 Use Table to convert each group: 0011 0101 . 0101 0100 2 0010 A 1010 3 0011 B 1011 4 0100 C 1100 5 0101 D 1101 3 5 . 5 416 6 0110 E 1110 7 0111 F 1111

  47. Converting Octal (Base 8) to Hex Hard way: 1. Convert octal to decimal (polynomial evaluation) 2. Convert decimal to hex (repeated division/multiplication) Easy way: 1. Convert octal to binary using short-cut (8 = 23) 2. Convert binary to hex using short-cut (16 = 24) Example: 12.658 ?16 1. 12.658 = 001 010 . 110 1012 = 001010.1101012 2. 001010.1101012 = 0000 1010 . 1101 01002 = 0A.D416

  48. Convert FA.CE16 to base 8 Hex Binary 1st: Base 16 to base 2 (16=24) 2nd: Base 2 to base 8 (8=23) 0001 0 0000 1 2 0010 3 0011 F A . C E16 11111010.110011102 0100 4 5 0101 1111 1010 . 1100 11102 011 111 010 110 011 100 . 6 0110 7 0111 8 1000 Octal Binary Octal Binary 9 1001 011 111 010 110 011 100 . A 1010 11111010.110011102 1 0 000 4 100 1011 001 5 101 B 3 C D 7 2 6 3 48 2 010 6 110 . 1100 3 011 7 111 1101 E 1110 F 1111

  49. Convert 7849 to base 3 Use power relationship (9 = 32) Each base 9 digit corresponds to 2 base 3 digits Base 9 Base 3 0 00 Use table to convert each digit: 7 8 1 01 49 2 02 3 10 4 11 5 12 21 22 113 6 20 7 21 8 22

  50. Review Problems Unsigned: Convert 110101.0101012 to hex (base 16) Convert unsigned FA.CE16 to base 8 Convert unsigned 7849 to base 3 Convert unsigned 256 to decimal Convert unsigned 2510 to base 7 Signed: Convert -75.7510to signed 2 s complement Convert 1001.01102from 2 s comp. to decimal

More Related Content