1. Number Systems Chapt. 2 Location in course textbook
Quantities/Counting (1 of 3) DecimalBinaryOctal Hexa- decimal p. 33
Quantities/Counting (2 of 3) DecimalBinaryOctal Hexa- decimal A B C D E F
Quantities/Counting (3 of 3) DecimalBinaryOctal Hexa- decimal Etc.
Conversion Among Bases The possibilities: Hexadecimal DecimalOctal Binary pp
Quick Example = = 31 8 = Base
Decimal to Decimal (just for fun) Hexadecimal DecimalOctal Binary Next slide…
=>5 x 10 0 = 5 2 x 10 1 = 20 1 x 10 2 = Base Weight
Binary to Decimal Hexadecimal DecimalOctal Binary
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
Example => 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 = Bit “0”
Octal to Decimal Hexadecimal DecimalOctal Binary
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
Example => 4 x 8 0 = 4 2 x 8 1 = 16 7 x 8 2 =
Hexadecimal to Decimal Hexadecimal DecimalOctal Binary
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
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 =
Decimal to Binary Hexadecimal DecimalOctal Binary
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.
Example = ? =
Octal to Binary Hexadecimal DecimalOctal Binary
Octal to Binary Technique Convert each octal digit to a 3-bit equivalent binary representation
Example = ? =
Hexadecimal to Binary Hexadecimal DecimalOctal Binary
Hexadecimal to Binary Technique Convert each hexadecimal digit to a 4-bit equivalent binary representation
Example 10AF 16 = ? A F AF 16 =
Decimal to Octal Hexadecimal DecimalOctal Binary
Decimal to Octal Technique Divide by 8 Keep track of the remainder
Example = ? =
Decimal to Hexadecimal Hexadecimal DecimalOctal Binary
Decimal to Hexadecimal Technique Divide by 16 Keep track of the remainder
Example = ? = 4D = D
Binary to Octal Hexadecimal DecimalOctal Binary
Binary to Octal Technique Group bits in threes, starting on right Convert to octal digits
Example = ? =
Binary to Hexadecimal Hexadecimal DecimalOctal Binary
Binary to Hexadecimal Technique Group bits in fours, starting on right Convert to hexadecimal digits
Example = ? B B = 2BB 16
Octal to Hexadecimal Hexadecimal DecimalOctal Binary
Octal to Hexadecimal Technique Use binary as an intermediary
Example = ? E = 23E 16
Hexadecimal to Octal Hexadecimal DecimalOctal Binary
Hexadecimal to Octal Technique Use binary as an intermediary
Example 1F0C 16 = ? 8 1 F 0 C F0C 16 =
Exercise – Convert... Don’t use a calculator! DecimalBinaryOctal Hexa- decimal AF Skip answer Answer
Exercise – Convert … DecimalBinaryOctal Hexa- decimal C AF Answer
Common Powers (1 of 2) Base 10 PowerPrefaceSymbol picop nanon micro millim 10 3 kilok 10 6 megaM 10 9 gigaG teraT Value
Common Powers (2 of 2) Base 2 PowerPrefaceSymbol 2 10 kilok 2 20 megaM 2 30 GigaG Value What is the value of “k”, “M”, and “G”? In computing, particularly w.r.t. memory, the base-2 interpretation generally applies
Example / 2 30 = In the lab… 1. Double click on My Computer 2. Right click on C: 3. Click on Properties
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.
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
Binary Addition (1 of 2) Two 1-bit values pp ABA + B “two”
Binary Addition (2 of 2) Two n-bit values Add individual bits Propagate carries E.g.,
Multiplication (1 of 3) Decimal (just for fun) pp x
Multiplication (2 of 3) Binary, two 1-bit values AB A B
Multiplication (3 of 3) Binary, two n-bit values As with decimal values E.g., 1110 x
Fractions Decimal to decimal (just for fun) pp =>4 x = x = x 10 0 =
Fractions Binary to decimal pp => 1 x 2 -4 = x 2 -3 = x 2 -2 = x 2 -1 = x 2 0 = x 2 1 =
Fractions Decimal to binary p x x x x x x etc
Exercise – Convert... Don’t use a calculator! DecimalBinaryOctal Hexa- decimal C.82 Skip answer Answer
Exercise – Convert … DecimalBinaryOctal Hexa- decimal …35.63…1D.CC… D C C.82 Answer
Representing one decimal number at a time How can we represent the ten decimal numbers (0-9) in binary code? Numeral BCD Representation We can represent any integer by a string of binary digits. For example, 749 can be represented in binary as: Binary Coded Decimal (BCD)
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 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 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 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 BCD – Binary Coded Decimal 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 BCD – Binary Coded Decimal Decimal BCD Number
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 EXCESS 3 CODE Decimal BCD Excess-3 Number Number Number
70 BCD-to-Excess-3 Table
71 BCD – Binary Coded Decimal Decimal BCD Number
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 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
DECIMALBINARYGRAY CODE GRAY CODE
75 VARIOUS DECIMAL CODES
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
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 xxxxxxx 1xxxxxxx xxxxxxx The original number is placed into the least significant portion The original number is placed into the least significant portion
2- Find the 9’s complement of and The 9’s complement of is = and the 9’s complement of is = ’s complement Examples
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 Bit n-1Bit n-2…….Bit 1Bit 0 -
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 = (1111) 2. The l’s complement of N is ( ) - N. = (1111) - N
The complement 1’s of is The 1’s complement of is l’s complement
10’s complement Examples Find the 10’s complement of and The 10’s complement of is = and the 10’s complement of is = Notice that it is the same as 9’s complement
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
2’s complement Example The 2’s complement of is The 2’s complement of is
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 is (invert the 0’s and 1’s) 2’s complement of is =
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 is 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.
Examples Finding the 2’s complement of ( ) 2 Method 1 – Simply complement each bit and then add 1 to the result. ( ) 2 [N] = 2’s complement = 1’s complement ( ) 2 +1 =( ) 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 = [N] =
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.
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.
1) BCD Numeric Format Every four bits represent one decimal digit. Use decimal values from 0 to 9
4-bit values above 9 are not used in BCD. 1) BCD Numeric Format The unused 4-bit values are: BCDDecimal
1) BCD Numeric Format Multi-digit decimal numbers are stored as multiple groups of 4 bits per digit.
2) Algorithms for Addition 1100 is not used in BCD.
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.
2) Algorithms for Addition A simple example of addition in BCD Incorrect BCD digit Add 6 Correct answer 1 4
Binary Coded Decimal ex1: dec-to-BCD (a) 35 (b) 98 (c) 170 (d) 2469 ex2: BCD-to-dec (a) (b) (c) Decimal Digit BCD Let’s crack these… Note: 1010, 1011, 1100, 1101, 1110, and 1111 are INVALID CODE!
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 If a carry results when 6 is added, simply add the carry to the next 4-bit group.
BCD Addition Try these: ex: Add the following numbers (a) (b) (c) (d) (e) (f) (g) (h)
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.
The Gray Code DecimalBinaryGray Code DecimalBinaryGray Code
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 to Gray code binary Gray
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 to binary Gray Binary
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
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)
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
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) Even parity 0 Odd parity
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, ,...) 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
Example Here is an example: A byte of data: Create the data word, leaving spaces for the parity bits: _ _ 1 _ _ 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 _ _ Even parity so set position 1 to a 0: 0 _ 1 _ _ Position 2 checks bits 2,3,6,7,10,11: 0 ? 1 _ _ Odd parity so set position 2 to a 1: _ _ Position 4 checks bits 4,5,6,7,12: ? _ Odd parity so set position 4 to a 1: _ Position 8 checks bits 8,9,10,11,12: ? Even parity so set position 8 to a 0: Code word:
Finding and fixing a bad bit The above example created a code word of Suppose the word that was received was 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 = 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
A byte of data: Create the data word, leaving spaces for the parity bits: _ _ 1 _ _ 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 _ _ Even parity so set position 1 to a 0: 0 _ 1 _ _ Position 2 checks bits 2,3,6,7,10,11: 0 ? 1 _ _ Odd parity so set position 2 to a 1: _ _ Position 4 checks bits 4,5,6,7,12: ? _ Odd parity so set position 4 to a 1: _ Position 8 checks bits 8,9,10,11,12: ? Even parity so set position 8 to a 0: Code word: