Presentation is loading. Please wait.

Presentation is loading. Please wait.

Number Systems Number Systems Stone Age: knots, some stone marks Roman Empire: more systematic notation I, II, III, IV, V, VI, VII.VIII, IX, X, C=100,

Similar presentations


Presentation on theme: "Number Systems Number Systems Stone Age: knots, some stone marks Roman Empire: more systematic notation I, II, III, IV, V, VI, VII.VIII, IX, X, C=100,"— Presentation transcript:

1 Number Systems Number Systems Stone Age: knots, some stone marks Roman Empire: more systematic notation I, II, III, IV, V, VI, VII.VIII, IX, X, C=100, D=500, M=1000, L=50 Concept of zero by –Maya- I century, Hindu-V century Positional-value systems: decimal, binary, octal, etc..

2 Positional-Value System The value of a digit (“digit” from Latin word for finger) depends on its position 5 6 7. 9 1 4 MSD Decimal LSD point Positional values 2 1 0 -1 -2 -3 (weights) 10 10 10 10 10 10 We will write ( 5 6 7. 9 1 4) 10

3 Binary: Base-2 Number System 1 0 1 1 1 1. 0 0 1 2 2 2 2 2 2 2 2 2 5 4 3 2 1 0 -1 -2 -3 We write: ( 1 0 1 1 1 1. 0 0 1 ) 2 base point or radix Digits are called bits

4 Binary Representation The basis of all digital data is binary representation. Binary - means ‘two’ –1, 0 –True, False –Hot, Cold –On, Off We must be able to handle more than just values for real world problems –1, 0, 56 –True, False, Maybe –Hot, Cold, LukeWarm, Cool –On, Off, Leaky

5 Number Systems To talk about binary data, we must first talk about number systems The decimal number system (base 10) you should be familiar with! –A digit in base 10 ranges from 0 to 9. –A digit in base 2 ranges from 0 to 1 (binary number system). A digit in base 2 is also called a ‘bit’. –A digit in base R can range from 0 to R-1 –A digit in Base 16 can range from 0 to 16-1 (0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F). Use letters A-F to represent values 10 to 15. Base 16 is also called Hexadecimal or just ‘Hex’.

6 Positional Number Systems The traditional number system is called a positional number system. A number is represented as a string of digits. Each digit position has a weight assoc. with it. Number’s value = a weighted sum of the digits

7 Positional Notation – more examples Value of number is determined by multiplying each digit by a weight and then summing. The weight of each digit is a POWER of the BASE and is determined by position. 953.78 = 9 x 10 2 + 5 x 10 1 + 3 x 10 0 + 7 x 10 -1 + 8 x 10 -2 = 900 + 50 + 3 +.7 +.08 = 953.78 % 1011.11 = 1x2 3 + 0x2 2 + 1x2 1 + 1x2 0 + 1x2 -1 + 1x2 -2 = 8 + 0 + 2 + 1 + 0.5 + 0.25 = 11.75 $ A2F = 10x16 2 + 2x16 1 + 15x16 0 = 10 x 256 + 2 x 16 + 15 x 1 = 2560 + 32 + 15 = 2607 decimal binary hex

8 Base 10, Base 2, Base 16 The textbook uses subscripts to represent different bases (ie. A2F 16, 953.78 10, 1011.11 2 ) We will use special symbols to represent the different bases. The default base will be decimal, no special symbol for base 10. The ‘$’ will be used for base 16 ( $A2F) The ‘%’ will be used for base 2 (%10101111) If ALL numbers on a page are the same base (ie, all in base 16 or base 2 or whatever) then no symbols will be used and a statement will be present that will state the base (ie, all numbers on this page are in base 16).

9 Common Powers 2 -3 = 0.125 2 -2 = 0.25 2 -1 = 0.5 2 0 = 1 2 1 = 2 2 2 = 4 2 3 = 8 2 4 = 16 2 5 =32 2 6 = 64 2 7 = 128 2 8 = 256 2 9 = 512 2 10 = 1024 2 11 = 2048 2 12 = 4096 16 0 = 1 = 2 0 16 1 = 16 = 2 4 16 2 = 256 = 2 8 16 3 = 4096 = 2 12 2 10 = 1024 = 1 K 2 20 = 1048576 = 1 M (1 Megabits) = 1024 K = 2 10 x 2 10 2 30 = 1073741824 = 1 G (1 Gigabits)

10 Octal and Hexadecimal (“Hex”) Numbers Octal = base 8 Hexadecimal = base 16 –Use A – F to represent the values 10 through 16 in each position.

11 Usefulness of Octal and Hex Numbers Useful for representing multi-bit binary numbers because their radices are integer multiples of 2. 10 0101 1010 1111. 1011 111 2 = 2 5 A F. B E 16 DecimalBinaryOctalHex 510155 611066 711177 81000108 91001119 10101012A 11101113B 12110014C 13110115D 14111016E 15111117F

12 Comparison of binary, decimal, octal and hexadecimal numbers examples of octal and hex numbers

13 Decimal to Hex Conversions Convert 53 to Hex 53/16 = 3, rem = 5 3 /16 = 0, rem = 3 53 = $ 35 = 3 x 16 1 + 5 x 16 0 = 48 + 5 = 53

14 Hex (base 16) to Binary Conversion Each Hex digit represents 4 bits. To convert a Hex number to Binary, simply convert each Hex digit to its four bit value. Hex Digits to binary: $ 0 = % 0000 $ 1 = % 0001 $2 = % 0010 $3 = % 0011 $4 = % 0100 $5 = % 0101 $6 = % 0110 $7 = % 0111 $8 = % 1000 Hex Digits to binary (cont): $ 9 = % 1001 $ A = % 1010 $ B = % 1011 $ C = % 1100 $ D = % 1101 $ E = % 1110 $ F = % 1111

15 Conversions: Hex to Binary, Binary to Hex $ A2F = % 1010 0010 1111 $ 345 = % 0011 0100 0101 Binary to Hex is just the opposite, create groups of 4 bits starting with least significant bits. If last group does not have 4 bits, then pad with zeros for unsigned numbers. % 1010001 = % 0101 0001 = $ 51 Padded with a zero Binary to hex conversion Hex to Binary conversion

16 A Trick! If faced with a large binary number that has to be converted to decimal, we first convert the binary number to HEX, then convert the HEX to decimal. Less work! % 110111110011 = % 1101 1111 0011 = $ D F 3 = 13 x 16 2 + 15 x 16 1 + 3x16 0 = 13 x 256 + 15 x 16 + 3 x 1 = 3328 + 240 + 3 = 3571 Of course, you can also use the binary, hex conversion feature on your calculator. You can use calculators on exam

17 Bah! I thought we were talking about Binary DATA!!! Yah, we were! How many binary DIGITS does it take to represent our data??

18 Binary Codes One Binary Digit (one bit) can take on values 0, 1. We can represent TWO values: (0 = hot, 1 = cold), (1 = True, 0 = False), (1 = on, 0 = off). Two Binary digits (two bits) can take on values of 00, 01, 10, 11. We can represent FOUR values: (00 = hot, 01 = warm, 10 = cool, 11 = cold). Three Binary digits (three bits) can take on values of 000, 001, 010, 011, 100, 101, 110, 111. We can represent 8 values 000 = Black, 001 = Red, 010 = Pink, 011 = Yellow, 100 = Brown, 101 = Blue, 110 = Green, 111 = White.

19 Binary Codes (cont.) N bits (or N binary Digits) can represent 2 N different values. (for example, 4 bits can represent 2 4 or 16 different values) N bits can take on unsigned decimal values from 0 to 2 N -1. Codes usually given in tabular form. 000 001 010 011 100 101 110 111 black red pink yellow brown blue green white

20 Code Conversions

21 ( ) 2 ( ) 4 ( ) 8 ( ) 16 To convert a binary number to a system which is base-2 z, group digits together by z and convert each group separately 100111.1010 ---> ( )16 2 7. A Converting from binary base hex as an example of base 2 Z

22 Conversion of Any Base to Decimal Converting from ANY base to decimal is done by multiplying each digit by its weight and summing. % 1011.11 = 1x2 3 + 0x2 2 + 1x2 1 + 1x2 0 + 1x2 -1 + 1x2 -2 = 8 + 0 + 2 + 1 + 0.5 + 0.25 = 11.75 Binary to Decimal Hex to Decimal $ A2F = 10x16 2 + 2x16 1 + 15x16 0 = 10 x 256 + 2 x 16 + 15 x 1 = 2560 + 32 + 15 = 2607

23 Conversion ( ) I ( ) 10 express number as a power series in I, and add all terms using decimal addition Converting from base I to decimal

24 Decimal-to-Radix-r Conversions Radix-r-to-decimal conversions are easy since we do arithmetic in decimal. However, decimal-to-radix-r conversions using decimal arithmetic is harder. To do the latter conversion, we convert the integer and fractional parts separately and add the results afterwards.

25 Convert ( ) 10 ( ) r Integer part: –Divide the number and all successive quotients by r –accumulate the remainders Fractional part: –Multiply the number and successive fractions by r –accumulate the integers

26 Conversion of Decimal Integer To ANY Base Divide Number N by base R until quotient is 0. Remainder at EACH step is a digit in base R, from Least Significant digit to Most significant digit. Convert 53 to binary 53/2 = 26, rem = 1 26/2 = 13, rem = 0 13/2 = 6, rem = 1 6 /2 = 3, rem = 0 3/2 = 1, rem = 1 1/2 = 0, rem = 1 53 = % 110101 = 1x2 5 + 1x2 4 + 0x2 3 + 1x2 2 + 0x2 1 + 1x2 0 = 32 + 16 + 0 + 4 + 0 + 1 = 53 Least Significant Digit Most Significant Digit

27 Decimal-to-Radix-r Conversions: Integer Part Successively divide number by r, taking remainder as result. Example: Convert 57 10 to binary. 57 / 2 = 28 remainder 1 (LSB) /2 = 14 remainder 0 /2 = 7 remainder 0 /2 = 3 remainder 1 /2 = 1 remainder 1 /2 = 0 remainder 1 (MSB) Answer: 111001 2

28 Decimal-to-Radix-r Conversions: Fractional Part Successively multiply number by r, taking integer part as result and chopping off integer part before next iteration. May be unending! Example: convert.3 10 to binary..3 * 2 =.6 integer part = 0.6 * 2 = 1.2 integer part = 1.2 * 2 =.4 integer part = 0.4 * 2 =.8 integer part = 0.8 * 2 = 1.6 integer part = 1.6 * 2 = 1.2 integer part = 1, etc. Answer =

29 More Conversion methods for common radices

30 Least Significant Digit Most Significant Digit 53 = % 110101 Most Significant Digit (has weight of 2 5 or 32). For base 2, also called Most Significant Bit (MSB). Always LEFTMOST digit. Least Significant Digit (has weight of 2 0 or 1). For base 2, also called Least Significant Bit (LSB). Always RIGHTMOST digit.

31 Binary Data in your life The computer screen on your Win 98 PC can be configured for different resolutions. One resolution is 600 x 800 x 8, which means that you have 600 dots vertically x 800 dots horizontally, with each dot using 8 bits to take on 256 different colors. (actually, a dot is called a pixel). Need 8 bits to represent 256 colors ( 2 8 = 256). Total number of bits needed to represent the screen is then: 600 x 800 x 8 = 3,840,000 bits (or just under 4 Mbits) Your video card must have at least this much memory on it. 1 Mbits = 1024 x 1024 = 2 10 x 2 10 = 2 20. 1 Kbits = 1024 = 2 10.

32 Addition and Subtraction Use same technique as decimal Except that the addition and subtraction tables are different Already seen addition table –Truth table for Sum and Cout function

33 Examples of decimal and corresponding binary additions

34 Examples of decimal and corresponding binary subtractions

35 Binary Addition and Subtraction Table

36 Subtraction table b in xyb out d 00000 00111 01001 01100 10011 10110 11000 11111 borrow in borrow out Discuss this method in comparison with previous method from the class to create a subtractor

37 Addition and Subtraction of Octal and Hexadecimal Numbers Not really too different But the addition and subtraction tables must be developed.

38 The concept of 10’s complement

39 digit complements in binary, octal, decimal and hexadecimal

40 Representation of Negative Numbers More accurately: representation of signed numbers –Signed-magnitude representation –Radix-complement representation 2’s-complement representation –Diminished radix-complement representation –Ones’ complement representation –Excess representations

41 Comparison of decimal and 4-bit numbers. Complements Decimal numbers, their two’s complements, ones’ complements, signed magniture and excess 2 m-1 binary codes Existence of two zeros! EXPLAIN

42 Signed-magnitude representation Also called, “sign-and-magnitude representation” A number consists of a magnitude and a symbol representing the sign Usually 0 means positive, 1 negative –Sign bit –Usually the entire number is represented with 1 sign bit to the left, followed by a number of magnitude bits

43 Machine arithmetic with signed- magnitude representation Takes several steps to add a pair of numbers –Examine signs of the addends –If same, add magnitudes and give the result the same sign as the operands –If different, must… Compare magnitude of the two operands Subtract smaller number from larger Give the result the sign of the larger operand For this reason the signed-magnitude representation is not as popular as one might think because of its “naturalness”

44 Complement number systems Negates a number by taking its complement instead of negating the sign Exact meaning of taking its complement is defined in various ways – will see Not natural for humans, but better for machine arithmetic Will describe 2 complement number systems –Radix complement – very popular in real computers –Diminished radix-complement – not very useful, may skip or not spend much time on it

45 Radix-complement number representation Must first decide how many bits to represent the number – say n. Complement of a number = r n – number Example: 4-bit decimal: –Original number = 3524 –10’s complement = 10000-3524 = 6476 0 and positive numbers: 0000-4999 Negative numbers: 5000-9999, where 9999 is ‘minus 1.’

46 Two’s-complement representation Just radix-complement when radix = 2 Used a lot in computers and other digital arithmetic circuits 0 and positive numbers: leftmost bit = 0 Negative numbers: leftmost bit = 1 To find a number’s complement – just flip all the bits and add 1 See graphical view – Fig. 2.3, p. 40.

47 Two’s-Comp Addition and Subtraction Rules Starting from 1000 (-8) on up, each successive 2’s comp number all the way to 0111 (+7) can be obtained by adding 1 to the previous one, ignoring any carries beyond the 4 th bit position Since addition is just an extension of ordinary counting, 2’s comp numbers can be added by ordinary binary addition! No different cases based on operands’ signs! Overflow possible –Occurs if result is out of range –To detect – happens if operands are the same sign but sum is a different sign of that of the operands

48 Modular Counting representation of Two’s Complements

49 Modular Counting representation of unsigned numbers Unsigned Numbers

50 Rules for addition and subtraction

51 DECIMAL CODES

52 Codes for Decimal Digits There are even codes for representing decimal digits. These codes use 4-bits for EACH decimal digits; it is NOT the same as converting from decimal to binary. BCD Code 0 = % 0000 1 = % 0001 2 = % 0010 3 = % 0011 4 = % 0100 5 = % 0101 6 = % 0110 7 = % 0111 8 = % 1000 9 = % 1001 In BCD code, each decimal digit simply represented by its binary equivalent. 96 = % 1001 0110 = $ 96 (BCD code) Advantage: easy to convert Disadvantage: takes more bits to store a number: 255 = % 1111 1111 = $ FF (binary code) 255 = % 0010 0101 0101 = $ 255 (BCD code) takes only 8 bits in binary, takes 12 bits in BCD.

53 Binary code for decimal numbers Any encoding needs at least 4 bits/decimal digit BCD (8421), a weighted code Packed BCD 2421 code –Self-complementing: the code for the 9s’ comp of any digit may be obtained by complementing the individual bits of the digit’s code word Excess 3 –Not a weighted code, but is also self-complementing –Since code follows standard binary counting sequence, standard binary counters can easily be made to count in excess-3

54 Biquinary code Uses more than 4 bits First 2 bits indicate whether the number is in the range 0-4 or 5-0 –One-hot Last 5 bits indicate which of the five numbers in the selected range is represented –Also one-hot Advantage: error-detection property. If any 1 bit in a code word is accidentally changed to the opposite value, the resulting code word doesn’t represent a decimal digit at all – flagged as error.

55 Codes for Characters Also need to represent Characters as digital data. The ASCII code (American Standard Code for Information Interchange) is a 7-bit code for Character data. Typically 8 bits are actually used with the 8th bit being zero or used for error detection (parity checking). 8 bits = 1 Byte. ‘A’ = % 01000001 = $41 ‘&’ = % 00100110 = $26 7 bits can only represent 2 7 different values (128). This enough to represent the Latin alphabet (A-Z, a-z, 0-9, punctuation marks, some symbols like $), but what about other symbols or other languages?

56 UNICODE UNICODE is a 16-bit code for representing alphanumeric data. With 16 bits, can represent 2 16 or 65536 different symbols. 16 bits = 2 Bytes per character. $0041-005A A-Z $0061-4007A a-z Some other alphabet/symbol ranges $3400-3d2d Korean Hangul Symbols $3040-318F Hiranga, Katakana, Bopomofo, Hangul $4E00-9FFF Han (Chinese, Japenese, Korean) UNICODE used by Web browsers, Java, most software these days.

57 Decimal codes Always two 1’s 0+3=3. 1+3=4 etc

58 GRAY CODES and mechanical encodings

59 A mechanical Encoding Disk Two bits change in natural binary code

60 Gray Code for decimal Digits Gray Code 0 = % 0000 1 = % 0001 2 = % 0011 3 = % 0010 4 = % 0110 5 = % 1110 6 = % 1010 7 = % 1011 8 = % 1001 9 = % 1000 A Gray code changes by only 1 bit for adjacent values. This is also called a ‘thumbwheel’ code because a thumbwheel for choosing a decimal digit can only change to an adjacent value (4 to 5 to 6, etc) with each click of the thumbwheel. This allows the binary output of the thumbwheel to only change one bit at a time; this can help reduce circuit complexity and also reduce signal noise.

61 Binary vs Gray Codes You should be able to design binary to Gray code converter in both directions

62 A mechanical disk for Gray Code Always one bit changes only

63 7 bit ASCII code You should be able to design a converter in both directions from any code to any other code!

64 Example of sequence generator machine with controlling counter machine

65 Controlling many devices with binary and one-hot codes

66 Error Correcting Codes

67 The concept of a hypercube

68

69

70 Even-parity and odd-parity codes

71 Space of codes for 7 bits with code words and non-code words

72 8-bit, distance 4 codes

73 Examples of Hamming Codes Hamming Codes

74 7 bit Hamming codes

75 Extended Hamming Codes

76 Two dimensional codes

77 Error-correcting code for a RAID system

78 Serial data transmission

79 Well-known codes for serial data transmission

80 Multiplication and Division Intro Multiplication and Division Intro

81 Binary multiplication Grammar school method for decimal: add a list of shifted multiplicands computed according to the digits of the multiplier Same method can be used in binary For two unsigned operands, the only possible values of the multiplier digits are 0 and 1 –Thus it’s trivial to form the shifted multiplicands

82 Binary multiplication in binary on a machine More convenient to add each shifted multiplicand as it is created to a partial product Will do an example. In general when we multiply an n-bit number by an m-bit number, the result requires at most n+m bits to express The shift-and-add algorithm requires m partial products and additions to obtain result, but the 1 st addition is trivial (adding to 0)

83 Long Division

84 Homework problem 1 Convert the following binary numbers to decimal: 1011011.0110 00110.11001

85 Homework problem 2 Convert from decimal to binary: 0.5 73.426 290.9

86 Convert from Binary to Octal: 1 101 011 110 111 11 011.101 1 Homework problem 3

87 Homework problem 4 Calculate 191+141 (Let’s first convert these to binary as an exercise.) Verify in decimal 210 – 109, calculate first binary numbers. Verify.

88 Homework problem 5 1.Discuss how to convert hex, binary integers to Decimal 2.Discuss how to convert decimal integers to hex, binary 3.Discuss how to convert hex to binary, binary to Hex 4.Explain why N binary digits can represent 2 N values, unsigned integers 0 to 2 N -1.

89 sources Bob Reese Wakerly Other from internet


Download ppt "Number Systems Number Systems Stone Age: knots, some stone marks Roman Empire: more systematic notation I, II, III, IV, V, VI, VII.VIII, IX, X, C=100,"

Similar presentations


Ads by Google