Presentation is loading. Please wait.

Presentation is loading. Please wait.

1. Number Systems Chapt. 2 Location in course textbook.

Similar presentations


Presentation on theme: "1. Number Systems Chapt. 2 Location in course textbook."— Presentation transcript:

1 1. Number Systems Chapt. 2 Location in course textbook

2 Quantities/Counting (1 of 3) DecimalBinaryOctal Hexa- decimal 0000 1111 21022 31133 410044 510155 611066 711177 p. 33

3 Quantities/Counting (2 of 3) DecimalBinaryOctal Hexa- decimal 81000108 91001119 10101012A 11101113B 12110014C 13110115D 14111016E 15111117F

4 Quantities/Counting (3 of 3) DecimalBinaryOctal Hexa- decimal 16100002010 17100012111 18100102212 19100112313 20101002414 21101012515 22101102616 23101112717 Etc.

5 Conversion Among Bases The possibilities: Hexadecimal DecimalOctal Binary pp. 40-46

6 Quick Example 25 10 = 11001 2 = 31 8 = 19 16 Base

7 Decimal to Decimal (just for fun) Hexadecimal DecimalOctal Binary Next slide…

8 125 10 =>5 x 10 0 = 5 2 x 10 1 = 20 1 x 10 2 = 100 125 Base Weight

9 Binary to Decimal Hexadecimal DecimalOctal Binary

10 Binary to Decimal Technique Multiply each bit by 2 n, where n is the “weight” of the bit The weight is the position of the bit, starting from 0 on the right Add the results

11 Example 101011 2 => 1 x 2 0 = 1 1 x 2 1 = 2 0 x 2 2 = 0 1 x 2 3 = 8 0 x 2 4 = 0 1 x 2 5 = 32 43 10 Bit “0”

12 Octal to Decimal Hexadecimal DecimalOctal Binary

13 Octal to Decimal Technique Multiply each bit by 8 n, where n is the “weight” of the bit The weight is the position of the bit, starting from 0 on the right Add the results

14 Example 724 8 => 4 x 8 0 = 4 2 x 8 1 = 16 7 x 8 2 = 448 468 10

15 Hexadecimal to Decimal Hexadecimal DecimalOctal Binary

16 Hexadecimal to Decimal Technique Multiply each bit by 16 n, where n is the “weight” of the bit The weight is the position of the bit, starting from 0 on the right Add the results

17 Example ABC 16 =>C x 16 0 = 12 x 1 = 12 B x 16 1 = 11 x 16 = 176 A x 16 2 = 10 x 256 = 2560 2748 10

18 Decimal to Binary Hexadecimal DecimalOctal Binary

19 Decimal to Binary Technique Divide by two, keep track of the remainder First remainder is bit 0 (LSB, least-significant bit) Second remainder is bit 1 Etc.

20 Example 125 10 = ? 2 2 125 62 1 2 31 0 2 15 1 2 7 1 2 3 1 2 1 1 2 0 1 125 10 = 1111101 2

21 Octal to Binary Hexadecimal DecimalOctal Binary

22 Octal to Binary Technique Convert each octal digit to a 3-bit equivalent binary representation

23 Example 705 8 = ? 2 7 0 5 111 000 101 705 8 = 111000101 2

24 Hexadecimal to Binary Hexadecimal DecimalOctal Binary

25 Hexadecimal to Binary Technique Convert each hexadecimal digit to a 4-bit equivalent binary representation

26 Example 10AF 16 = ? 2 1 0 A F 0001 0000 1010 1111 10AF 16 = 0001000010101111 2

27 Decimal to Octal Hexadecimal DecimalOctal Binary

28 Decimal to Octal Technique Divide by 8 Keep track of the remainder

29 Example 1234 10 = ? 8 8 1234 154 2 8 19 2 8 2 3 8 0 2 1234 10 = 2322 8

30 Decimal to Hexadecimal Hexadecimal DecimalOctal Binary

31 Decimal to Hexadecimal Technique Divide by 16 Keep track of the remainder

32 Example 1234 10 = ? 16 1234 10 = 4D2 16 16 1234 77 2 16 4 13 = D 16 0 4

33 Binary to Octal Hexadecimal DecimalOctal Binary

34 Binary to Octal Technique Group bits in threes, starting on right Convert to octal digits

35 Example 1011010111 2 = ? 8 1 011 010 111 1 3 2 7 1011010111 2 = 1327 8

36 Binary to Hexadecimal Hexadecimal DecimalOctal Binary

37 Binary to Hexadecimal Technique Group bits in fours, starting on right Convert to hexadecimal digits

38 Example 1010111011 2 = ? 16 10 1011 1011 2 B B 1010111011 2 = 2BB 16

39 Octal to Hexadecimal Hexadecimal DecimalOctal Binary

40 Octal to Hexadecimal Technique Use binary as an intermediary

41 Example 1076 8 = ? 16 1 0 7 6 001 000 111 110 2 3 E 1076 8 = 23E 16

42 Hexadecimal to Octal Hexadecimal DecimalOctal Binary

43 Hexadecimal to Octal Technique Use binary as an intermediary

44 Example 1F0C 16 = ? 8 1 F 0 C 0001 1111 0000 1100 1 7 4 1 4 1F0C 16 = 17414 8

45 Exercise – Convert... Don’t use a calculator! DecimalBinaryOctal Hexa- decimal 33 1110101 703 1AF Skip answer Answer

46 Exercise – Convert … DecimalBinaryOctal Hexa- decimal 331000014121 117111010116575 4511110000117031C3 4311101011116571AF Answer

47 Common Powers (1 of 2) Base 10 PowerPrefaceSymbol 10 -12 picop 10 -9 nanon 10 -6 micro  10 -3 millim 10 3 kilok 10 6 megaM 10 9 gigaG 10 12 teraT Value.000000000001.000000001.000001.001 1000 1000000 1000000000 1000000000000

48 Common Powers (2 of 2) Base 2 PowerPrefaceSymbol 2 10 kilok 2 20 megaM 2 30 GigaG Value 1024 1048576 1073741824 What is the value of “k”, “M”, and “G”? In computing, particularly w.r.t. memory, the base-2 interpretation generally applies

49 Example / 2 30 = In the lab… 1. Double click on My Computer 2. Right click on C: 3. Click on Properties

50 Exercise – Free Space Determine the “free space” on all drives on a machine in the lab Drive Free space BytesGB A: C: D: E: etc.

51 Review – multiplying powers For common bases, add powers 2 6  2 10 = 2 16 = 65,536 or… 2 6  2 10 = 64  2 10 = 64k a b  a c = a b+c

52 Binary Addition (1 of 2) Two 1-bit values pp. 36-38 ABA + B 000 011 101 1110 “two”

53 Binary Addition (2 of 2) Two n-bit values Add individual bits Propagate carries E.g., 10101 21 + 11001 + 25 101110 46 11

54 Multiplication (1 of 3) Decimal (just for fun) pp. 39 35 x 105 175 000 35 3675

55 Multiplication (2 of 3) Binary, two 1-bit values AB A  B 000 010 100 111

56 Multiplication (3 of 3) Binary, two n-bit values As with decimal values E.g., 1110 x 1011 1110 1110 0000 1110 10011010

57 Fractions Decimal to decimal (just for fun) pp. 46-50 3.14 =>4 x 10 -2 = 0.04 1 x 10 -1 = 0.1 3 x 10 0 = 3 3.14

58 Fractions Binary to decimal pp. 46-50 10.1011 => 1 x 2 -4 = 0.0625 1 x 2 -3 = 0.125 0 x 2 -2 = 0.0 1 x 2 -1 = 0.5 0 x 2 0 = 0.0 1 x 2 1 = 2.0 2.6875

59 Fractions Decimal to binary p. 50 3.14579.14579 x 2 0.29158 x 2 0.58316 x 2 1.16632 x 2 0.33264 x 2 0.66528 x 2 1.33056 etc. 11.001001...

60 Exercise – Convert... Don’t use a calculator! DecimalBinaryOctal Hexa- decimal 29.8 101.1101 3.07 C.82 Skip answer Answer

61 Exercise – Convert … DecimalBinaryOctal Hexa- decimal 29.811101.110011…35.63…1D.CC… 5.8125101.11015.645.D 3.10937511.0001113.073.1C 12.50781251100.1000001014.404C.82 Answer

62 Representing one decimal number at a time How can we represent the ten decimal numbers (0-9) in binary code? Numeral0123456789 BCD Representation 0000000100100011010001010110011110001001 We can represent any integer by a string of binary digits. For example, 749 can be represented in binary as: 011101001001 Binary Coded Decimal (BCD)

63 63 How Many Bits Are Necessary to Represent Something? 1 bit can represent two (2 1 ) symbols  either a 0 or a 1 2 bits can represent four (2 2 ) symbols  00 or 01 or 10 or 11 3 bits can represent eight (2 3 ) symbols  000 or 001 or 011 or 111 or 100 or 110 or 101 or 010 4 bits can represent sixteen (2 4 ) symbols 5 bits can represent 32 (2 5 ) symbols 6 bits can represent 64 (2 6 ) symbols 7 bits can represent 128 (2 7 ) symbols 8 bits (a byte) can represent 256 (2 8 ) symbols n bits can represent (2 n ) symbols! So…how many bits are necessary for all of us in class to have a unique binary ID? Are two bits enough? Three? Four? Five? Six? Seven?

64 64 Binary Codes A binary code is a group of n bits that assume up to 2 n distinct combinations of 1’s and 0’s with each combination representing one element of the set that is being coded.

65 65 Binary Digital Codes Gray Code – Gray Code BCD 2421 – BCD 2421 code BCD XS 3 – BCD Excess 3 code BCD 8421 – BCD 8421 code EBCDIC – Extended BCD Interchange Code

66 66 BCD – Binary Coded Decimal 6 3 49 0110 0011 0100 1001 BCD is a convention for mapping binary numbers to decimal numbers. When the decimal numbers are represented in BCD, each decimal digit is represented by the equivalent BCD code. Example :BCD Representation of Decimal 6349

67 67 BCD – Binary Coded Decimal Decimal BCD Number 0 0000 1 0001 2 0010 3 0011 4 0100 5 0101 6 0110 7 0111 8 1000 9 1001

68 68 The excess-3 code is obtained by adding 3 (0011) to the corresponding BCD equivalent binary number. Excess-3 have a self-complementing property EXCESS 3 CODE

69 69 EXCESS 3 CODE Decimal BCD Excess-3 Number Number Number 0 00000011 1 00010100 2 00100101 3 00110110 4 01000111 5 01011000 6 01101001 7 01111010 8 10001011 9 10011100

70 70 BCD-to-Excess-3 Table

71 71 BCD – Binary Coded Decimal Decimal BCD Number 100001 0000 1210001 0010 0001 2340010 0011 0100 10030001 0000 0000 0011

72 72 2421 and excess-3 have a self-complementing property 9’s complement is obtained by 1’s to 0’s and 0’s to 1’s. Useful property when doing arithmetic operations with signed complement representation. This code is widely used in instruments and electronic calculators. BCD 2421 CODE

73 73 Unweighted and is not an arithmetic code Only one bit changes from one code to the next in the sequence Gray code can be any amounts of bits. The gray code originated when digital logic circuits were built from vacuum tubes and electromechanical relays Counters generated tremendous power demands and noise spikes when many bits changed at once Using gray code counters, any increment or decrement changed only one bit GRAY CODE

74 DECIMALBINARYGRAY CODE 00000 10001 200100011 3 0010 401000110 501010111 601100101 701110100 810001100 910011101 1010101111 1110111110 1211001010 1311011011 1411101001 1511111000 GRAY CODE

75 75 VARIOUS DECIMAL CODES

76 Sign Magnitude An extra bit in the most significant position is designated as the sign bit which is to the left of an unsigned integer. The unsigned integer is the magnitude. A 0 in the sign bit means positive, and a 1 means negative xxx xxxx x

77 Sign Extension - complement For positive number, a 0 is used to stuff the remaining positions. For negative number, a 1 is used to stuff the remaining positions. 0xxxxxxx 000000000xxxxxxx 1xxxxxxx 111111111xxxxxxx The original number is placed into the least significant portion The original number is placed into the least significant portion

78 2- Find the 9’s complement of 546700 and 12389 The 9’s complement of 546700 is 999999 - 546700= 453299 and the 9’s complement of 12389 is 99999- 12389 = 87610. 9’s complement Examples 5 4 6 7 0 - 0 999 999 453 299 1238 - 9 99999 87610

79 l’s complement For binary numbers, r = 2 and r — 1 = 1, r-1’s complement is the l’s complement. The l’s complement of N is (2n - 1) - N. Digit n Digit n-1 Next digit First digit 11111 Bit n-1Bit n-2…….Bit 1Bit 0 -

80 l’s complement Find r-1 complement for binary number N with four binary digits. r-1 complement for binary means 2-1 complement or 1’s complement. n = 4, we have 2 4 = (10000) 2 and 2 4 - 1 = (1111) 2. The l’s complement of N is (2 4 - 1) - N. = (1111) - N

81 The complement 1’s of 1011001 is 0100110 0 11 0 0 - 1 111111 100110 00111 - 1 111111 110000 1 1 0 The 1’s complement of 0001111 is 1110000 0 1 1 l’s complement

82 10’s complement Examples Find the 10’s complement of 546700 and 12389 The 10’s complement of 546700 is 1000000 - 546700= 453300 and the 10’s complement of 12389 is 100000 - 12389 = 87611. Notice that it is the same as 9’s complement + 1. 54 6 7 0 - 0 000 0 00 45 3 3 00 1238 - 9 100000 87611 1

83 For binary numbers, r = 2, r’s complement is the 2’s complement. The 2’s complement of N is 2 n - N. 2’s complement Digit n Digit n-1 Next digit First digit 00000 - 1

84 2’s complement Example The 2’s complement of 1011001 is 0100111 The 2’s complement of 0001111 is 1110001 011 00 - 1 000000 100111 00111 - 1 110001 1 0 0 0 1 1 00000001

85 Fast Methods for 2’s Complement Method 1: The 2’s complement of binary number is obtained by adding 1 to the l’s complement value. Example: 1’s complement of 101100 is 010011 (invert the 0’s and 1’s) 2’s complement of 101100 is 010011 + 1 = 010100

86 Fast Methods for 2’s Complement Method 2: The 2’s complement can be formed by leaving all least significant 0’s and the first 1 unchanged, and then replacing l’s by 0’s and 0’s by l’s in all other higher significant bits. Example: The 2’s complement of 1101100 is 0010100 Leave the two low-order 0’s and the first 1 unchanged, and then replacing 1’s by 0’s and 0’s by 1’s in the four most significant bits.

87 Examples Finding the 2’s complement of (01100101) 2 Method 1 – Simply complement each bit and then add 1 to the result. (01100101) 2 [N] = 2’s complement = 1’s complement (10011010) 2 +1 =(10011011) 2 Method 2 – Starting with the least significant bit, copy all the bits up to and including the first 1 bit and then complement the remaining bits. N = 0 1 1 0 0 1 0 1 [N] = 1 0 0 1 1 0 1 1

88 Binary Coded Decimal Introduction: Although binary data is the most efficient storage scheme; every bit pattern represents a unique, valid value. However, some applications may not be desirable to work with binary data. For instance, the internal components of digital clocks keep track of the time in binary. The binary value must be converted to decimal before it can be displayed.

89 Binary Coded Decimal Because a digital clock is preferable to store the value as a series of decimal digits, where each digit is separately represented as its binary equivalent, the most common format used to represent decimal data is called binary coded decimal, or BCD.

90 1) BCD Numeric Format Every four bits represent one decimal digit.  Use decimal values from 0 to 9

91  4-bit values above 9 are not used in BCD. 1) BCD Numeric Format The unused 4-bit values are: BCDDecimal 101010 101111 110012 110113 111014 111115

92 1) BCD Numeric Format Multi-digit decimal numbers are stored as multiple groups of 4 bits per digit.

93 2) Algorithms for Addition  1100 is not used in BCD.

94 2) Algorithms for Addition Two errors will occurs in a standard binary adder. 1) The result is not a valid BCD digit. 2) A valid BCD digit, but not the correct result. Solution: You need to add 6 to the result generated by a binary adder.

95 2) Algorithms for Addition A simple example of addition in BCD. 0101 + 1001 1110 + 0110 1 0100 5 + 9 Incorrect BCD digit Add 6 Correct answer 1 4

96 Binary Coded Decimal ex1: dec-to-BCD (a) 35 (b) 98 (c) 170 (d) 2469 ex2: BCD-to-dec (a) 10000110 (b) 001101010001 (c) 1001010001110000 Decimal Digit 0123456789 BCD0000000100100011010001010110011110001001 Let’s crack these… Note: 1010, 1011, 1100, 1101, 1110, and 1111 are INVALID CODE!

97 BCD Addition BCD is a numerical code and can be used in arithmetic operations. Here is how to add two BCD numbers: Add the two BCD numbers, using the rules for basic binary addition. If a 4-bit sum is equal to or less than 9, it is a valid BCD number. If a 4-bit sum > 9, or if a carry out of the 4-bit group is generated it is an invalid result. Add 6 (0110) to a 4-bit sum in order to skip the six the invalid states and return the code to 8421. If a carry results when 6 is added, simply add the carry to the next 4-bit group.

98 BCD Addition Try these: ex: Add the following numbers (a) 0011+0100 (b) 00100011 + 00010101 (c) 10000110 + 00010011 (d) 010001010000 + 010000010111 (e) 1001 + 0100 (f) 1001 + 1001 (g) 00010110 + 00010101 (h) 01100111 + 01010011

99 The Gray Code The Gray code is unweighted and is not an arithmetic code. There are no specific weights assigned to the bit positions. Important: the Gray code exhibits only a single bit change from one code word to the next in sequence. This property is important in many applications, such as shaft position encoders.

100 The Gray Code DecimalBinaryGray Code 00000 10001 200100011 3 0010 401000110 501010111 601100101 701110100 DecimalBinaryGray Code 810001100 910011101 1010101111 1110111110 1211001010 1311011011 1411101001 1511111000

101 The Gray Code Binary-to-Gray code conversion The MSB in the Gray code is the same as corresponding MSB in the binary number. Going from left to right, add each adjacent pair of binary code bits to get the next Gray code bit. Discard carries. ex: convert 10110 2 to Gray code 1 + 0 + 1 + 1 + 0 binary 1 1 1 0 1 Gray

102 The Gray Code Gray-to-Binary Conversion The MSB in the binary code is the same as the corresponding bit in the Gray code. Add each binary code bit generated to the Gray code bit in the next adjacent position. Discard carries. ex: convert the Gray code word 11011 to binary 1 1 0 1 1 Gray + + + + 1 0 0 1 0 Binary

103 Alphanumeric Codes Represent numbers and alphabetic characters. Also represent other characters such as symbols and various instructions necessary for conveying information. The ASCII is the most common alphanumeric code. ASCII = American Standard Code for Information Interchange

104 ASCII ASCII has 128 characters and symbols represented by a 7-bit binary code. (the first 32) – control characters graphics symbols (can be printed or displayed)

105 Introduction(Error Checking Code) All transmitted signals will contain some rate of errors (>0%) because noise is always present If a communications line experiences too much noise, the signal will be lost or corrupted Once an error is detected, a system may perform some action, or may do nothing but simply let the data in error be discarded Popular error detection methods: Simple Parity (add a 1 or 0 to the end of each seven bits) Longitudinal Parity or Longitudinal Redundancy Check (LRC) Cyclic Redundancy Checksum (CRC), or called Polynomial checking

106 Simple Parity Occasionally known as vertical redundancy check Add an additional bit to a string of bits: Even parity The 0 or 1 added to the string produces an even number of 1s (including the parity bit) Odd parity The 0 or 1 added … an odd number of 1s (including the parity bit) 0101010 1 Even parity 0 Odd parity

107 The key to the Hamming Code is the use of extra parity bits to allow the identification of a single error. Create the code word as follows: Mark all bit positions that are powers of two as parity bits. (positions 1, 2, 4, 8, 16, 32, 64, etc.) All other bit positions are for the data to be encoded. (positions 3, 5, 6, 7, 9, 10, 11, 12, 13, 14, 15, 17, etc.) Each parity bit calculates the parity for some of the bits in the code word. The position of the parity bit determines the sequence of bits that it alternately checks and skips. Position 1: check 1 bit, skip 1 bit, check 1 bit, skip 1 bit, etc. (1,3,5,7,9,11,13,15,...) Position 2: check 2 bits, skip 2 bits, check 2 bits, skip 2 bits, etc. (2,3,6,7,10,11,14,15,...) Position 4: check 4 bits, skip 4 bits, check 4 bits, skip 4 bits, etc. (4,5,6,7,12,13,14,15,20,21,22,23,...) Position 8: check 8 bits, skip 8 bits, check 8 bits, skip 8 bits, etc. (8-15,24-31,40-47,...) Position 16: check 16 bits, skip 16 bits, check 16 bits, skip 16 bits, etc. (16-31,48-63,80-95,...) Position 32: check 32 bits, skip 32 bits, check 32 bits, skip 32 bits, etc. (32-63,96-127,160- 191,...) etc. Set a parity bit to 1 if the total number of ones in the positions it checks is odd. Set a parity bit to 0 if the total number of ones in the positions it checks is even. Calculating the Hamming Code

108 Example Here is an example: A byte of data: 10011010 Create the data word, leaving spaces for the parity bits: _ _ 1 _ 0 0 1 _ 1 0 1 0 Calculate the parity for each parity bit (a ? represents the bit position being set): Position 1 checks bits 1,3,5,7,9,11: ? _ 1 _ 0 0 1 _ 1 0 1 0. Even parity so set position 1 to a 0: 0 _ 1 _ 0 0 1 _ 1 0 1 0 Position 2 checks bits 2,3,6,7,10,11: 0 ? 1 _ 0 0 1 _ 1 0 1 0. Odd parity so set position 2 to a 1: 0 1 1 _ 0 0 1 _ 1 0 1 0 Position 4 checks bits 4,5,6,7,12: 0 1 1 ? 0 0 1 _ 1 0 1 0. Odd parity so set position 4 to a 1: 0 1 1 1 0 0 1 _ 1 0 1 0 Position 8 checks bits 8,9,10,11,12: 0 1 1 1 0 0 1 ? 1 0 1 0. Even parity so set position 8 to a 0: 0 1 1 1 0 0 1 0 1 0 1 0 Code word: 011100101010.

109 Finding and fixing a bad bit The above example created a code word of 011100101010. Suppose the word that was received was 011100101110 instead. Then the receiver could calculate which bit was wrong and correct it. The method is to verify each check bit. Write down all the incorrect parity bits. Doing so, you will discover that parity bits 2 and 8 are incorrect. It is not an accident that 2 + 8 = 10, and that bit position 10 is the location of the bad bit. In general, check each parity bit, and add the positions that are wrong, this will give you the location of the bad bit. Try one yourself Test if these code words are correct, assuming they were created using an even parity Hamming Code. If one is incorrect, indicate what the correct code word should have been. Also, indicate what the original data was. 010101100011 111110001100 000010001010

110 A byte of data: 10011010 Create the data word, leaving spaces for the parity bits: _ _ 1 _ 0 0 1 _ 1 0 1 0 Calculate the parity for each parity bit (a ? represents the bit position being set): Position 1 checks bits 1,3,5,7,9,11: ? _ 1 _ 0 0 1 _ 1 0 1 0. Even parity so set position 1 to a 0: 0 _ 1 _ 0 0 1 _ 1 0 1 0 Position 2 checks bits 2,3,6,7,10,11: 0 ? 1 _ 0 0 1 _ 1 0 1 0. Odd parity so set position 2 to a 1: 0 1 1 _ 0 0 1 _ 1 0 1 0 Position 4 checks bits 4,5,6,7,12: 0 1 1 ? 0 0 1 _ 1 0 1 0. Odd parity so set position 4 to a 1: 0 1 1 1 0 0 1 _ 1 0 1 0 Position 8 checks bits 8,9,10,11,12: 0 1 1 1 0 0 1 ? 1 0 1 0. Even parity so set position 8 to a 0: 0 1 1 1 0 0 1 0 1 0 1 0 Code word: 011100101010.


Download ppt "1. Number Systems Chapt. 2 Location in course textbook."

Similar presentations


Ads by Google