1. number systems chapt. 2 location in course textbook

Post on 04-Jan-2016

225 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

1. Number Systems

Chapt. 2

Location in course textbook

Quantities/Counting (1 of 3)

Decimal Binary Octal

Hexa-decimal

0 0 0 0

1 1 1 1

2 10 2 2

3 11 3 3

4 100 4 4

5 101 5 5

6 110 6 6

7 111 7 7

p. 33

Quantities/Counting (2 of 3)

Decimal Binary Octal

Hexa-decimal

8 1000 10 8

9 1001 11 9

10 1010 12 A

11 1011 13 B

12 1100 14 C

13 1101 15 D

14 1110 16 E

15 1111 17 F

Quantities/Counting (3 of 3)

Decimal Binary Octal

Hexa-decimal

16 10000 20 10

17 10001 21 11

18 10010 22 12

19 10011 23 13

20 10100 24 14

21 10101 25 15

22 10110 26 16

23 10111 27 17 Etc.

Conversion Among Bases

The possibilities:

Hexadecimal

Decimal Octal

Binary

pp. 40-46

Quick Example

2510 = 110012 = 318 = 1916

Base

Decimal to Decimal (just for fun)

Hexadecimal

Decimal Octal

Binary

Next slide…

12510 => 5 x 100 = 52 x 101 = 201 x 102 = 100

125

Base

Weight

Binary to Decimal

Hexadecimal

Decimal Octal

Binary

Binary to Decimal

Technique Multiply each bit by 2n, 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

1010112 => 1 x 20 = 11 x 21 = 20 x 22 = 01 x 23 = 80 x 24 = 01 x 25 = 32

4310

Bit “0”

Octal to Decimal

Hexadecimal

Decimal Octal

Binary

Octal to Decimal

Technique Multiply each bit by 8n, 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

7248 => 4 x 80 = 42 x 81 = 167 x 82 = 448

46810

Hexadecimal to Decimal

Hexadecimal

Decimal Octal

Binary

Hexadecimal to Decimal

Technique Multiply each bit by 16n, 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

ABC16 => C x 160 = 12 x 1 = 12 B x 161 = 11 x 16 = 176 A x 162 = 10 x 256 = 2560

274810

Decimal to Binary

Hexadecimal

Decimal Octal

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.

Example12510 = ?2

2 125 62 12 31 02 15 12 7 12 3 12 1 12 0 1

12510 = 11111012

Octal to Binary

Hexadecimal

Decimal Octal

Binary

Octal to Binary

Technique Convert each octal digit to a 3-bit equivalent

binary representation

Example7058 = ?2

7 0 5

111 000 101

7058 = 1110001012

Hexadecimal to Binary

Hexadecimal

Decimal Octal

Binary

Hexadecimal to Binary

Technique Convert each hexadecimal digit to a 4-bit

equivalent binary representation

Example10AF16 = ?2

1 0 A F

0001 0000 1010 1111

10AF16 = 00010000101011112

Decimal to Octal

Hexadecimal

Decimal Octal

Binary

Decimal to Octal

Technique Divide by 8 Keep track of the remainder

Example123410 = ?8

8 1234 154 28 19 28 2 38 0 2

123410 = 23228

Decimal to Hexadecimal

Hexadecimal

Decimal Octal

Binary

Decimal to Hexadecimal

Technique Divide by 16 Keep track of the remainder

Example123410 = ?16

123410 = 4D216

16 1234 77 216 4 13 = D16 0 4

Binary to Octal

Hexadecimal

Decimal Octal

Binary

Binary to Octal

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

Example10110101112 = ?8

1 011 010 111

1 3 2 7

10110101112 = 13278

Binary to Hexadecimal

Hexadecimal

Decimal Octal

Binary

Binary to Hexadecimal

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

Example10101110112 = ?16

10 1011 1011

2 B B

10101110112 = 2BB16

Octal to Hexadecimal

Hexadecimal

Decimal Octal

Binary

Octal to Hexadecimal

Technique Use binary as an intermediary

Example10768 = ?16

1 0 7 6

001 000 111 110

2 3 E

10768 = 23E16

Hexadecimal to Octal

Hexadecimal

Decimal Octal

Binary

Hexadecimal to Octal

Technique Use binary as an intermediary

Example1F0C16 = ?8

1 F 0 C

0001 1111 0000 1100

1 7 4 1 4

1F0C16 = 174148

Exercise – Convert ...

Don’t use a calculator!

Decimal Binary Octal

Hexa-decimal

33

1110101

703

1AF

Skip answer Answer

Exercise – Convert …

Decimal Binary Octal

Hexa-decimal

33 100001 41 21

117 1110101 165 75

451 111000011 703 1C3

431 110101111 657 1AF

Answer

Common Powers (1 of 2)

Base 10Power Preface Symbol

10-12 pico p

10-9 nano n

10-6 micro

10-3 milli m

103 kilo k

106 mega M

109 giga G

1012 tera T

Value

.000000000001

.000000001

.000001

.001

1000

1000000

1000000000

1000000000000

Common Powers (2 of 2)

Base 2Power Preface Symbol

210 kilo k

220 mega M

230 Giga G

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

Example

/ 230 =

In the lab…1. Double click on My Computer2. 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

Bytes GB

A:

C:

D:

E:

etc.

Review – multiplying powers

For common bases, add powers

26 210 = 216 = 65,536

or…

26 210 = 64 210 = 64k

ab ac = ab+c

Binary Addition (1 of 2)

Two 1-bit values

pp. 36-38

A B A + B

0 0 0

0 1 1

1 0 1

1 1 10

“two”

Binary Addition (2 of 2)

Two n-bit values Add individual bits Propagate carries E.g.,

10101 21+ 11001 + 25 101110 46

11

Multiplication (1 of 3)

Decimal (just for fun)

pp. 39

35x 105 175 000 35 3675

Multiplication (2 of 3)

Binary, two 1-bit values

A B A B

0 0 0

0 1 0

1 0 0

1 1 1

Multiplication (3 of 3)

Binary, two n-bit values As with decimal values E.g.,

1110 x 1011 1110 1110 0000 111010011010

Fractions

Decimal to decimal (just for fun)

pp. 46-50

3.14 => 4 x 10-2 = 0.041 x 10-1 = 0.1

3 x 100 = 3 3.14

Fractions

Binary to decimal

pp. 46-50

10.1011 => 1 x 2-4 = 0.06251 x 2-3 = 0.1250 x 2-2 = 0.01 x 2-1 = 0.50 x 20 = 0.01 x 21 = 2.0 2.6875

Fractions

Decimal to binary

p. 50

3.14579

.14579x 20.29158x 20.58316x 21.16632x 20.33264x 20.66528x 21.33056

etc.11.001001...

Exercise – Convert ...

Don’t use a calculator!

Decimal Binary Octal

Hexa-decimal

29.8

101.1101

3.07

C.82

Skip answer Answer

Exercise – Convert …

Decimal Binary Octal

Hexa-decimal

29.8 11101.110011… 35.63… 1D.CC…

5.8125 101.1101 5.64 5.D

3.109375 11.000111 3.07 3.1C

12.5078125 1100.10000010 14.404 C.82

Answer

• Representing one decimal number at a time

• How can we represent the ten decimal numbers (0-9) in binary code?

NumeralNumeral00112233445566778899

BCD RepresentationBCD Representation00000000000100010010001000110011010001000101010101100110011101111000100010011001

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

How Many Bits Are Necessary to Represent Something? 1 bit can represent two (21) symbols

either a 0 or a 1 2 bits can represent four (22) symbols

00 or 01 or 10 or 11 3 bits can represent eight (23) symbols

000 or 001 or 011 or 111 or 100 or 110 or 101 or 010 4 bits can represent sixteen (24) symbols 5 bits can represent 32 (25) symbols 6 bits can represent 64 (26) symbols 7 bits can represent 128 (27) symbols 8 bits (a byte) can represent 256 (28) symbols n bits can represent (2n) 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 CodesA binary code is a group of n bits that assume up to 2n 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

6 3 4 9

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

BCD – Binary Coded DecimalDecimal BCD

Number Number

0 0000 1 0001 2 0010 3 0011 4 0100 5 0101 6 0110 7 0111 8 1000 9 1001

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 CODEDecimal BCD Excess-3Number Number Number

0 0000 0011 1 0001 0100 2 0010 0101 3 0011 0110 4 0100 0111 5 0101 1000 6 0110 1001 7 0111 1010 8 1000 1011 9 1001 1100

70

BCD-to-Excess-3 Table

71

BCD – Binary Coded Decimal

Decimal BCDNumber Number

10 0001 0000 121 0001 0010 0001 234 0010 0011 0100 1003 0001 0000 0000 0011

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

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

DECIMAL BINARY GRAY CODE

0 0000 0000

1 0001 0001

2 0010 0011

3 0011 0010

4 0100 0110

5 0101 0111

6 0110 0101

7 0111 0100

8 1000 1100

9 1001 1101

10 1010 1111

11 1011 1110

12 1100 1010

13 1101 1011

14 1110 1001

15 1111 1000

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 xxxxx

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 isplaced into the least significant portion

The original number isplaced into the least significant portion

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

9 9 9 9 9 9

4 5 3 2 9 9

1 2 3 8- 9

9 9 9 9 9

8 7 6 1 0

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

Next digit

First digit

1 1 1 1 1

Bit n-1 Bit n-2 ……. Bit 1 Bit 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 24 = (10000)2 and 24 - 1 = (1111)2.

The l’s complement of N is (24 - 1) - N. = (1111) - N

The complement 1’s of1011001 is 0100110

0 1 1 0 0- 1

1 1 1 1 1 1

1 0 0 1 1 0

0 0 1 1 1- 1

1 1 1 1 1 1

1 1 0 0 0 0

1

1

0

The 1’s complement of0001111 is 1110000

0

1

1

l’s complement

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.

5 4 6 7 0- 0

0 0 0 0 0 0

4 5 3 3 0 0

1 2 3 8- 9

1 0 0 0 0 0

8 7 6 1 1

1

For binary numbers, r = 2,

r’s complement is the 2’s complement.

The 2’s complement of N is 2n - N.

2’s complement

Digit n

Digit n-1

Next digit

Next digit

First digit

0 0 0 0 0

-1

2’s complement Example

The 2’s complement of1011001 is 0100111

The 2’s complement of0001111 is 1110001

0 1 1 0 0- 1

0 0 0 0 0 0

1 0 0 1 1 1

0 0 1 1 1- 1

1 1 0 0 0 1

1

0

0

0

1

1

0 0 0 0 0 001

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

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.

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

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:

BCD Decimal

1010 10

1011 11

1100 12

1101 13

1110 14

1111 15

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.

0101

+ 1001

1110

+ 0110

1 0100

5

+ 9

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) 10000110

(b) 001101010001

(c) 1001010001110000

Decimal Digit

0 1 2 3 4 5 6 7 8 9

BCD 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001

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 8421. 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) 0011+0100(b) 00100011 + 00010101(c) 10000110 + 00010011(d) 010001010000 + 010000010111(e) 1001 + 0100(f) 1001 + 1001(g) 00010110 + 00010101(h) 01100111 + 01010011

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 CodeDecimal Binary Gray Code

0 0000 0000

1 0001 0001

2 0010 0011

3 0011 0010

4 0100 0110

5 0101 0111

6 0110 0101

7 0111 0100

Decimal Binary Gray Code

8 1000 1100

9 1001 1101

10 1010 1111

11 1011 1110

12 1100 1010

13 1101 1011

14 1110 1001

15 1111 1000

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 101102 to Gray code

1 + 0 + 1 + 1 + 0 binary

1 1 1 0 1 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 11011 to binary

1 1 0 1 1 Gray

+ + + +1 0 0 1 0 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)

0 1 0 1 0 1 01 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,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

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 0Calculate 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.

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

A byte of data: 10011010Create 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.

top related