Transcript
Page 1: EE 261 – Introduction to Logic Circuits Module #2 Page 1 EE 261 – Introduction to Logic Circuits Module #2 – Number Systems Topics A.Number System Formation

EE 261 – Introduction to Logic Circuits Module #2Page 1

EE 261 – Introduction to Logic Circuits

Module #2 – Number Systems

• TopicsA. Number System Formation

B. Base Conversions

C. Binary Arithmetic

D. Signed Numbers

E. Signed Arithmetic

F. Binary Codes

• Textbook Reading Assignments 2.1–2.16

• Practice Problems 2.1, 2.5, 2.6, 2.7, 2.8, 2.11, 2.12

• Graded Components of this Module 2 homeworks, 2 discussions, 1 quiz

(all online)

Page 2: EE 261 – Introduction to Logic Circuits Module #2 Page 1 EE 261 – Introduction to Logic Circuits Module #2 – Number Systems Topics A.Number System Formation

EE 261 – Introduction to Logic Circuits Module #2Page 2

EE 261 – Introduction to Logic Circuits

Module #2 – Number Systems

• What you should be able to do after this module

Convert numbers between bases (decimal, binary, octal, hexadecimal) Perform arithmetic (both signed & unsigned) using other bases Create and Decode various binary codes (BCD, Gray, ASCII, Parity)

Page 3: EE 261 – Introduction to Logic Circuits Module #2 Page 1 EE 261 – Introduction to Logic Circuits Module #2 – Number Systems Topics A.Number System Formation

EE 261 – Introduction to Logic Circuits Module #2Page 3

Number Systems

• Number System - a system that contains a set of numbers/symbols/characters and at least one operation (+, -, …)

• BASE or RADIX - the number of symbols in the number system - humans use Base10 (why?) - computers use Base2 (why?)

• Positional Number System - we can represent 10 unique quantities w/ our Base10 system - what if we want more? - we can add a "leading" digit to our number that has increased "weight”

ex) 0 1

: 9 10

11 : 99100

101

Page 4: EE 261 – Introduction to Logic Circuits Module #2 Page 1 EE 261 – Introduction to Logic Circuits Module #2 – Number Systems Topics A.Number System Formation

EE 261 – Introduction to Logic Circuits Module #2Page 4

Number Systems

• Radix Point - place in the string of digits at which numbers represent either whole or fractional. ex) 125.178

• p - Number of digits to the LEFT of the radix point.

• n - Number of digits to the RIGHT of the radix point.

• d - Digits in the system, described with a positional subscript (NOTE: if the radix point is missing, we assume it is to the right of the #)

• r - Radix or Base (Base10, r=10)

• i - Position - starting at 0 - increasing to the left of the radix point

- negative to the right of the radix point

• Weight - each digit has a weight based on its position = r i

- we multiply the digit by its weight to find how much value that digit represents

Page 5: EE 261 – Introduction to Logic Circuits Module #2 Page 1 EE 261 – Introduction to Logic Circuits Module #2 – Number Systems Topics A.Number System Formation

EE 261 – Introduction to Logic Circuits Module #2Page 5

Number Systems

• Value - the value of a number is the sum of each digit multiplied by its corresponding weight.

Example: Given the BASE 10 (r=10) number 327.2

What is p? p=3What is n? n=1Write the digit notation? d2 d1 d0 . d-1

What is the weight for each position? 102 101 100 .10-1

Show the expanded decimal equivalent? = 3(102) + 2(101 ) +7(100 ) + 2(10-1 ) = 327.2

Why all this framework? Because this generic format works for all Bases.

1p

ni

ii rdD

Page 6: EE 261 – Introduction to Logic Circuits Module #2 Page 1 EE 261 – Introduction to Logic Circuits Module #2 – Number Systems Topics A.Number System Formation

EE 261 – Introduction to Logic Circuits Module #2Page 6

Number Systems

• Binary - A number system with 2 symbols (BASE=2 or r=2). - The symbols are 0 and 1 - each symbol is called a "bit" - we’ll give a subscript to the number to indicate its base

ex) 101010 (decimal) 10102 (binary)

- 4 bits are called a "Nibble" - 8 bits are called a "Byte" - the leftmost bit in a string is called the Most Significant (MSB) or High Order - the rightmost bit in a string is called the Least Significant (LSB) or Low Order

Page 7: EE 261 – Introduction to Logic Circuits Module #2 Page 1 EE 261 – Introduction to Logic Circuits Module #2 – Number Systems Topics A.Number System Formation

EE 261 – Introduction to Logic Circuits Module #2Page 7

Number Systems

• Binary Systems

Example: Given the Binary number 10011

What is p? p=5What is n? n=0What is r? r=2Write the bit notation? b4 b3 b2 b1 b0

What is the weight for each position? 24 23 22 21 20

Show the expanded decimal equivalent? B = 1(24) + 0(23) +0(22 ) + 1(21 ) + 1(20 ) = 1(16) + 0(8) + 0(4) + 1(2) +1(1) = 1910

1p

ni

ii rbB

Page 8: EE 261 – Introduction to Logic Circuits Module #2 Page 1 EE 261 – Introduction to Logic Circuits Module #2 – Number Systems Topics A.Number System Formation

EE 261 – Introduction to Logic Circuits Module #2Page 8

Base Conversions

• Base - the number of symbols in a number system - we instinctively know decimal - we've talked about Binary (two symbol) - there are other bases of interest in digital systems - the bases we typically care about are powers of 2 (or associated with Binary) - these bases are typically used to represent a lot of "bits"

ex) it's hard to describe the value of a 64-bit bus in 1's and 0's

• Octal - A number system with 8 symbols - 0,1,2,3,4,5,6,7 - each digit in this system is equivalent to 3-bits - it is a positional number system ex) 0 1

: 7 10

11 : 17 20

Page 9: EE 261 – Introduction to Logic Circuits Module #2 Page 1 EE 261 – Introduction to Logic Circuits Module #2 – Number Systems Topics A.Number System Formation

EE 261 – Introduction to Logic Circuits Module #2Page 9

Base Conversions

• Hexadecimal - A number system with 16 symbols - we use alphabetic characters as symbols in the set above 9 - 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F - each digit in this system is equivalent to 4-bits - it is a positional number system

ex) 0 1

: 9 A

B C

D E F 10 11 : 1F 20 :

Page 10: EE 261 – Introduction to Logic Circuits Module #2 Page 1 EE 261 – Introduction to Logic Circuits Module #2 – Number Systems Topics A.Number System Formation

EE 261 – Introduction to Logic Circuits Module #2Page 10

Base Conversions

• How the Bases Relate to Each Other

Decimal Binary Octal Hexadecimal

Base10 Base2 Base8 Base16

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

- these are the commonly used bases in digital systems, we'd like to be able to convert between them

Page 11: EE 261 – Introduction to Logic Circuits Module #2 Page 1 EE 261 – Introduction to Logic Circuits Module #2 – Number Systems Topics A.Number System Formation

EE 261 – Introduction to Logic Circuits Module #2Page 11

Base Conversions

• Converting to Decimal

- we sum the products of each digit value with its positional weight

- this works for whole and fractional digits- this works for Binary to Decimal- this works for Octal to Decimal- this works for Hex to Decimal

1p

ni

ii rdD

Page 12: EE 261 – Introduction to Logic Circuits Module #2 Page 1 EE 261 – Introduction to Logic Circuits Module #2 – Number Systems Topics A.Number System Formation

EE 261 – Introduction to Logic Circuits Module #2Page 12

Base Conversions

• Base Conversion – Binary to Decimal

- each digit has a “weight” of ri that depends on the position of the digit - multiply each digit by its “weight”

- sum the resultant products

ex) Convert 1011 to decimal

23 22 21 20 (weight) 1 0 1 1

= 1•(23) + 0• (22) + 1• (21) + 1• (20) = 1•(8) + 0• (4) + 1• (2) + 1• (1) = 8 + 0 + 2 + 1 = 11 Decimal

Page 13: EE 261 – Introduction to Logic Circuits Module #2 Page 1 EE 261 – Introduction to Logic Circuits Module #2 – Number Systems Topics A.Number System Formation

EE 261 – Introduction to Logic Circuits Module #2Page 13

Base Conversions

• Base Conversion – Binary to Decimal with Fractions

- the weight of the binary digits have negative positions

ex) Convert 1011.101 to decimal

23 22 21 20 2-1 2-2 2-3 1 0 1 1 . 1 0 1

= 1•(23) + 0• (22) + 1• (21) + 1• (20) + 1• (2-1) + 0• (2-2) + 1• (2-3) = 1•(8) + 0• (4) + 1• (2) + 1• (1) + 1• (0.5) + 0• (0.25) + 1• (0.125)

= 8 + 0 + 2 + 1 + 0.5 + 0 + 0.125 = 11.625 Decimal

Page 14: EE 261 – Introduction to Logic Circuits Module #2 Page 1 EE 261 – Introduction to Logic Circuits Module #2 – Number Systems Topics A.Number System Formation

EE 261 – Introduction to Logic Circuits Module #2Page 14

Base Conversions

• Base Conversion – Hex to Decimal

- the same process as “binary to decimal” except the weights are now BASE 16 - NOTE (A=10, B=11, C=12, D=13, E=14, F=15)

ex) Convert 2BC from Hex to decimal

162 161 160 (weight) 2 B C

= 2• (162) + B• (161) + C• (160) = 2•(256) + 11• (16) + 12• (1) = 512 + 176 + 12 = 700 Decimal

Page 15: EE 261 – Introduction to Logic Circuits Module #2 Page 1 EE 261 – Introduction to Logic Circuits Module #2 – Number Systems Topics A.Number System Formation

EE 261 – Introduction to Logic Circuits Module #2Page 15

Base Conversions

• Base Conversion – Hex to Decimal with Fractions

- the fractional digits have negative weights (BASE 16) - NOTE (A=10, B=11, C=12, D=13, E=14, F=15)

ex) Convert 2BC.F to decimal

162 161 160 16-1 (weight) 2 B C . F

= 2• (162) + B• (161) + C• (160) + F• (16-1) = 2•(256) + 11• (16) + 12• (1) + 15• (0.0625) = 512 + 176 + 12 + 0.938 = 700.938 Decimal

Page 16: EE 261 – Introduction to Logic Circuits Module #2 Page 1 EE 261 – Introduction to Logic Circuits Module #2 – Number Systems Topics A.Number System Formation

EE 261 – Introduction to Logic Circuits Module #2Page 16

Base Conversions

• Base Conversion – Decimal to Binary

- the decimal number is divided by 2, the remainder is recorded - the quotient is then divided by 2, the remainder is recorded - the process is repeated until the quotient is zero

ex) Convert 11 decimal to binary

Quotient Remainder 2 11 5 1 LSB

2 5 2 1

2 2 1 0

2 1 0 1 MSB

= 1011 binary

Page 17: EE 261 – Introduction to Logic Circuits Module #2 Page 1 EE 261 – Introduction to Logic Circuits Module #2 – Number Systems Topics A.Number System Formation

EE 261 – Introduction to Logic Circuits Module #2Page 17

Base Conversions

• Base Conversion – Decimal to Binary with Fractions

- the fraction is converted to binary separately - the fraction is multiplied by 2, the 0th position digit is recorded - the remaining fraction is multiplied by 2, the 0th digit is recorded - the process is repeated until the fractional part is zero

ex) Convert 0.375 decimal to binary

Product 0th Digit 0.375•2 0.75 0 MSB

0.75•2 1.50 1 0.5•2 1.00 1 LSB

0.375 decimal = 0.011 binary

finished

Page 18: EE 261 – Introduction to Logic Circuits Module #2 Page 1 EE 261 – Introduction to Logic Circuits Module #2 – Number Systems Topics A.Number System Formation

EE 261 – Introduction to Logic Circuits Module #2Page 18

Base Conversions

• Base Conversion – Decimal to Hex

- the same procedure is used as before but with BASE 16 as the divisor/multiplier ex) Convert 420.625 decimal to hex

1st, convert the integer part…

Quotient Remainder

16 420 26 4 LSB

16 26 1 10

16 1 0 1 MSB = 1A4

2nd, convert the fractional part…

Product 0th Digit

0.625•16 10.00 10 MSB = 0.A

420.625 decimal = 1A4.A hexadecimal

Page 19: EE 261 – Introduction to Logic Circuits Module #2 Page 1 EE 261 – Introduction to Logic Circuits Module #2 – Number Systems Topics A.Number System Formation

EE 261 – Introduction to Logic Circuits Module #2Page 19

Base Conversions

• Base Conversion – Octal to Decimal / Decimal to Octal - the same procedure is used as before but with BASE 8 as the divisor/multiplier

Page 20: EE 261 – Introduction to Logic Circuits Module #2 Page 1 EE 261 – Introduction to Logic Circuits Module #2 – Number Systems Topics A.Number System Formation

EE 261 – Introduction to Logic Circuits Module #2Page 20

Base Conversions

• Base Conversion of "Powers of 2"

- converting bases that are powers of 2 are simple due to straight forward mapping - An Octal digital represents 3 bits - A Hex digit represents 4 bits

Page 21: EE 261 – Introduction to Logic Circuits Module #2 Page 1 EE 261 – Introduction to Logic Circuits Module #2 – Number Systems Topics A.Number System Formation

EE 261 – Introduction to Logic Circuits Module #2Page 21

Base Conversions

• Converting Binary to Hexadecimal

- every 4 binary bits represents one HEX digit - begin the groups of four at the LSB - if necessary, fill with leading 0’s to form the groups of four ex) Convert 111010100 from Binary to Hex

0001 1101 0100

1 D 4 Hex, notice that we had to fill with MSB 0's to get groups of four…

- This works for fractions too. The only difference is that the grouping starts at the Radix Point

ex) Convert 0.11 from Binary to Octal

0.1100

0.C

Page 22: EE 261 – Introduction to Logic Circuits Module #2 Page 1 EE 261 – Introduction to Logic Circuits Module #2 – Number Systems Topics A.Number System Formation

EE 261 – Introduction to Logic Circuits Module #2Page 22

Base Conversions

• Converting Binary to Octal

- every 3 binary bits represents one OCTAL digit - begin the groups of three at the LSB - if necessary, fill with leading 0’s to form the groups of three ex) Convert 111010100 from Binary to Octal

111 010 100

7 2 4 Octal

ex) Convert 10100 from Binary to Octal

010 100

1 4 Octal, note we had to fill with 0's on the MSB side

Page 23: EE 261 – Introduction to Logic Circuits Module #2 Page 1 EE 261 – Introduction to Logic Circuits Module #2 – Number Systems Topics A.Number System Formation

EE 261 – Introduction to Logic Circuits Module #2Page 23

Base Conversions

• Converting Hex to Binary

- each HEX digit is made up of four binary bits ex) Convert ABC Hex to Binary

A B C

= 1010 1011 1100 = 101010111100

Page 24: EE 261 – Introduction to Logic Circuits Module #2 Page 1 EE 261 – Introduction to Logic Circuits Module #2 – Number Systems Topics A.Number System Formation

EE 261 – Introduction to Logic Circuits Module #2Page 24

Base Conversions

• Converting Octal to Binary

- each Octal digit is made up of three binary bits ex) Convert 567 Octal to Binary

5 6 7

= 101 110 111 = 101110111

Page 25: EE 261 – Introduction to Logic Circuits Module #2 Page 1 EE 261 – Introduction to Logic Circuits Module #2 – Number Systems Topics A.Number System Formation

EE 261 – Introduction to Logic Circuits Module #2Page 25

Base Conversions

• Terminology

NIBBLE = 4 bits

BYTE = 8 bits

- you should be familiar with converting Binary Nibbles to Hex & Dec

- there is a table on page 28 of your textbook which lists the basic conversions

Page 26: EE 261 – Introduction to Logic Circuits Module #2 Page 1 EE 261 – Introduction to Logic Circuits Module #2 – Number Systems Topics A.Number System Formation

EE 261 – Introduction to Logic Circuits Module #2Page 26

Binary Arithmetic

• Addition and Subtraction

- same as BASE 10 math, remember borrows and carries

Addition Table

0 0 1 1 + 0 + 1 + 0 + 1

0 1 1 10 Carry

Subtraction Table 10 0 0 1 1 - 0 - 1 - 0 - 1

0 1 1 0

Need to "Borrow" from a more significant bit

Page 27: EE 261 – Introduction to Logic Circuits Module #2 Page 1 EE 261 – Introduction to Logic Circuits Module #2 – Number Systems Topics A.Number System Formation

EE 261 – Introduction to Logic Circuits Module #2Page 27

Binary Arithmetic

• Binary Addition

- same as BASE 10 addition - need to keep track of the carry bit for a given system size (n), i.e., 4-bit, 8-bit, 16-bit,… ex) Add the binary numbers 1011 and 1001

1 1 1 0 1 1

1 0 0 1

+_____ 1 0 1 0 0

Carry Bit

Page 28: EE 261 – Introduction to Logic Circuits Module #2 Page 1 EE 261 – Introduction to Logic Circuits Module #2 – Number Systems Topics A.Number System Formation

EE 261 – Introduction to Logic Circuits Module #2Page 28

Binary Arithmetic

• Binary Subtraction

- same as BASE 10 subtraction - need to keep track of the borrow bit for a given system size (n), i.e., 4-bit, 8-bit, 16-bit,… ex) Subtract the binary numbers 1010 and 0011

1 10 0 10 0 10

1 0 1 00 0 1 1

-________ 0 1 1 1

Borrow bits : if necessary, we could assume a borrow from an even higher significant bit

Page 29: EE 261 – Introduction to Logic Circuits Module #2 Page 1 EE 261 – Introduction to Logic Circuits Module #2 – Number Systems Topics A.Number System Formation

EE 261 – Introduction to Logic Circuits Module #2Page 29

Signed Numbers

• Negative Numbers

- So far, we've dealt with Positive numbers - The real world has Negative numbers - We need a method to represent negatives in binary - However, our number system doesn't have a "-", just 0's and 1's

• Sign Bit

- We will use the MSB to represent a "+" or "-"

0 = Positive 1 = Negative

Page 30: EE 261 – Introduction to Logic Circuits Module #2 Page 1 EE 261 – Introduction to Logic Circuits Module #2 – Number Systems Topics A.Number System Formation

EE 261 – Introduction to Logic Circuits Module #2Page 30

Signed Numbers

• Signed Magnitude Representation

- a negative number system (there is more than one) - uses the MSB as the sign bit - the remaining LSB's represent the number

ex) 85 dec = 1010101 +85 dec = 01010101 (additional sign bit adds one bit to the number) -85 dec = 11010101

• Is this Efficient?

- The number of unique combinations that a number can represents is given by:

N = rx N = # of unique combinations x = # of digits in the number (p + n) r = base ex) 2-bits: N=22 = 4 (00, 01, 10, 11) 7-bits: N=27 = 128 8-bits: N=28 = 256

Page 31: EE 261 – Introduction to Logic Circuits Module #2 Page 1 EE 261 – Introduction to Logic Circuits Module #2 – Number Systems Topics A.Number System Formation

EE 261 – Introduction to Logic Circuits Module #2Page 31

Signed Numbers

• Signed Magnitude Range

- The Range of Signed Magnitude is given by:

-(2x-1 - 1) < NSM < (2x-1 -1)

ex) if we use 8-bits, the range is: -(28-1 - 1) < NSM < (28-1 -1)

-127 < NSM < +127

- This is only 255 unique numbers

- But, if we are using 8-bits, there should be 28 unique numbers, or 256?

- This is because in Signed Magnitude, there are two representations for Zero

0 0000000 = +0 1 0000000 = -0

Page 32: EE 261 – Introduction to Logic Circuits Module #2 Page 1 EE 261 – Introduction to Logic Circuits Module #2 – Number Systems Topics A.Number System Formation

EE 261 – Introduction to Logic Circuits Module #2Page 32

Signed Numbers

• Advantages of Signed Magnitude

- Very easy to understand and use- the binary number is simply represented in binary, then a sign bit is added

• Disadvantages of Signed Magnitude Representation

- We loose a possible number by having +0, and -0. - This also creates a gap in our number list, which makes simple math harder - Addition/Subtraction in general are more difficult

Algorithm : if ( signs are the same)

- add and give same sign

else if (signs are different)

- compare magnitudes - subtract smaller from larger - give the result the sign of larger number

Page 33: EE 261 – Introduction to Logic Circuits Module #2 Page 1 EE 261 – Introduction to Logic Circuits Module #2 – Number Systems Topics A.Number System Formation

EE 261 – Introduction to Logic Circuits Module #2Page 33

Signed Numbers

• Complement Numbers

- Complementing a Binary Number means: 0 changes to 1 1 changes to 0

- using this technique, number can be a "complemented" to find the negative representation, then the arithmetic becomes much simpler

- the ones we care about are

1) "Radix Complement" (2's complement for binary) 2) "1's Complement

Page 34: EE 261 – Introduction to Logic Circuits Module #2 Page 1 EE 261 – Introduction to Logic Circuits Module #2 – Number Systems Topics A.Number System Formation

EE 261 – Introduction to Logic Circuits Module #2Page 34

Signed Numbers

• Radix Complement

- i.e., 10's complement, 2's complement

- Technique to get the Radix Complement:

- subtract current number from rx

Dr-comp = rn - Dorig - Rules: - The MSB is still the sign bit (0="+", 1="-") - Now that we're subtracting, we can't have arbitrary number of bits… x is predetermined and fixed

- A simpler method is :

1) Complement all digits in Dorig

2) Add 1 to the result, ignore any carry-out

Page 35: EE 261 – Introduction to Logic Circuits Module #2 Page 1 EE 261 – Introduction to Logic Circuits Module #2 – Number Systems Topics A.Number System Formation

EE 261 – Introduction to Logic Circuits Module #2Page 35

Signed Numbers

• 2's Complement

- this is Radix Complement on a BASE2 number system - straight forward to use the "complement and add 1" technique

ex) Give the 8-bit, 2's complement representation of -1710

1710 = 000100012 (Notice that the MSB is the sign bit, 0=+)

Step 1: 11101110 (we first complement all bits)

Step 2: + 1 (we then add 1)

11101111 (Notice the Sign Bit is negative)

- these 8-bits represent -1710 in 2's complement

Page 36: EE 261 – Introduction to Logic Circuits Module #2 Page 1 EE 261 – Introduction to Logic Circuits Module #2 – Number Systems Topics A.Number System Formation

EE 261 – Introduction to Logic Circuits Module #2Page 36

Signed Numbers

• 2's Complement Checking

- We can convert back to find Original magnitude and do checking

ex) Give the 8-bit, 2's complement representation of -1710

-1710 = 11101111 2's Comp (Notice that the MSB is the sign bit, 1="-")

Step 1: 00010000 (we first complement all bits)

Step 2: + 1 (we then add 1)

00010001 (Notice the Sign Bit is positive)

- these 8-bits represent +1710,Which is what we originally started with,

Page 37: EE 261 – Introduction to Logic Circuits Module #2 Page 1 EE 261 – Introduction to Logic Circuits Module #2 – Number Systems Topics A.Number System Formation

EE 261 – Introduction to Logic Circuits Module #2Page 37

Signed Numbers

• 2's Complement Range

- We need to know how many numbers we can represent using this system

- Notice that we are still using a bit for the sign…

- BUT, we don't duplicate Zero in this system

ex) 00000000 = 010

10000000 = -12810

- The Range of 2's Comp is given by:

-(2x-1) < N2Comp < (2x-1 -1)

ex) if we use 8-bits, the range is:

-(28-1) < N2Comp < (28-1 -1)

-128 < N2Comp < +127

- There are now 256 unique numbers, this is a more efficient use of bits

Page 38: EE 261 – Introduction to Logic Circuits Module #2 Page 1 EE 261 – Introduction to Logic Circuits Module #2 – Number Systems Topics A.Number System Formation

EE 261 – Introduction to Logic Circuits Module #2Page 38

Signed Numbers

• 1's Complement

- In 2's complement, the codes are asymmetric

Lowest 2's Comp # = 1000 00002Comp = -12810

Highest 2's Comp # = 0111 11112Comp = +12710

- This is good because we have all 256 possible numbers that 8-bits can give us

- 1's Comp is similar, but it gives us symmetry around Zero

- To find the 1's Comp, we subtract current number from (rx -1)

D1Comp = (rn -1) - Dorig

Page 39: EE 261 – Introduction to Logic Circuits Module #2 Page 1 EE 261 – Introduction to Logic Circuits Module #2 – Number Systems Topics A.Number System Formation

EE 261 – Introduction to Logic Circuits Module #2Page 39

Signed Numbers

• 1's Complement

- Or we can use the simple way

1) Complement all the #'s (Don't add 1)

ex) Give the 8-bit, 1's complement representation of -1710

1710 = 000100012 (Notice that the MSB is the sign bit, 0=+)

Step 1: 111011101Comp (complement all bits)

Page 40: EE 261 – Introduction to Logic Circuits Module #2 Page 1 EE 261 – Introduction to Logic Circuits Module #2 – Number Systems Topics A.Number System Formation

EE 261 – Introduction to Logic Circuits Module #2Page 40

Signed Numbers

• 1's Complement Range

- The Range of 1's Complement is given by:

-(2x-1 - 1) < NSM < (2x-1 -1)

- Once again, we have two values for Zero

00000000 = +0 11111111 = -0

Page 41: EE 261 – Introduction to Logic Circuits Module #2 Page 1 EE 261 – Introduction to Logic Circuits Module #2 – Number Systems Topics A.Number System Formation

EE 261 – Introduction to Logic Circuits Module #2Page 41

Signed Numbers

• Negative Representation

- We have covered 3 different "signed" codes

- You need to KNOW THE CODE you are using

ex) Represent -2210

1) Signed Magnitude : 10010110SM

2) 2's Complement : 111010102Comp

3) 1's Complement : 111010011Comp

Page 42: EE 261 – Introduction to Logic Circuits Module #2 Page 1 EE 261 – Introduction to Logic Circuits Module #2 – Number Systems Topics A.Number System Formation

EE 261 – Introduction to Logic Circuits Module #2Page 42

Signed Arithmetic

• Two’s Compliment Arithmetic

- Two's complement has advantages when going into Hardware

- Two's complement addition is straight forward because the numbers are in sequential order (+1) from their least significant (1000 0000 ) to their most significant (0111 1111)

- There is only one value for Zero, so "avoiding the gap" isn't necessary

Page 43: EE 261 – Introduction to Logic Circuits Module #2 Page 1 EE 261 – Introduction to Logic Circuits Module #2 – Number Systems Topics A.Number System Formation

EE 261 – Introduction to Logic Circuits Module #2Page 43

Signed Arithmetic

• Two’s Compliment Addition

- Addition of two’s compliment numbers is performed just like standard binary addition. - However, the carry bit is ignored

Page 44: EE 261 – Introduction to Logic Circuits Module #2 Page 1 EE 261 – Introduction to Logic Circuits Module #2 – Number Systems Topics A.Number System Formation

EE 261 – Introduction to Logic Circuits Module #2Page 44

Signed Arithmetic

• Two’s Compliment Subtraction

- We can build a subtraction circuit out of the same hardware as an adder

- 2's Comp inherently adds negative numbers so

- to subtract, we can just complement one number, and add it.

ex) Subtract 8dec from 15dec

15dec = 0000 1111 8dec = 0000 1000 -> two’s compliment -> invert 1111 0111 add1 + 1 ----------------- 1111 1000 = -8dec Now Add: 15 + (-8) = %0000 1111 %1111 1000 +_________ 1 0000 0111 = 7dec

Disregard Carry

Page 45: EE 261 – Introduction to Logic Circuits Module #2 Page 1 EE 261 – Introduction to Logic Circuits Module #2 – Number Systems Topics A.Number System Formation

EE 261 – Introduction to Logic Circuits Module #2Page 45

Signed Arithmetic

• Two’s Compliment Overflow

- If a two’s compliment arithmetic operation results in a number that is outside the range of representation (i.e., 8bits : -128 < N < +127), an “overflow” has occurred.

ex) -100dec – 100dec- = -200dec (can’t represent)

- There are three cases when overflow occurs

1) Sum of like signs results in answer with opposite sign 2) Negative – Positive = Positive 3) Positive – Negative = Negative

- Boolean logic can be used to detect these situations.

Page 46: EE 261 – Introduction to Logic Circuits Module #2 Page 1 EE 261 – Introduction to Logic Circuits Module #2 – Number Systems Topics A.Number System Formation

EE 261 – Introduction to Logic Circuits Module #2Page 46

Signed Arithmetic

• Remember 2's Comp Range

- The Range of 2's Comp is given by:

-(2x-1) < N2Comp < (2x-1 -1)

ex) if we use 8-bits, the range is:

-(28-1) < N2Comp < (28-1 -1)

-128 < N2Comp < +127

• What goes on in real Hardware?

- A generic, Binary adder circuit is created

- the user must be aware of when 2's complement is being used

- additional circuitry checks for "Overflow"

Page 47: EE 261 – Introduction to Logic Circuits Module #2 Page 1 EE 261 – Introduction to Logic Circuits Module #2 – Number Systems Topics A.Number System Formation

EE 261 – Introduction to Logic Circuits Module #2Page 47

Binary Codes

• Codes

- a string of x-bits that represent information

- we've seen codes already using the binary # system

1) Signed Magnitude 2) 2's Complement 3) 1's Complement

- the same information can be encoded differently

- it's up to the engineer to KNOW THE CODE that is being used

Code Word - the term to represent the discrete string of bits that make up the information

ex) 4-bit code words in a stream of information 1111 0100 0100

word

Page 48: EE 261 – Introduction to Logic Circuits Module #2 Page 1 EE 261 – Introduction to Logic Circuits Module #2 – Number Systems Topics A.Number System Formation

EE 261 – Introduction to Logic Circuits Module #2Page 48

Binary Codes

• Binary Coded Decimal (BCD)

- Sometimes we wish to represent an individual decimal digit as a binary representation (i.e., 7-segment display to eliminate a decoder)

- We do this by using 4 binary digits.

Decimal BCD 0 0000 1 0001 ex) Represent 17dec 2 0010 3 0011 Binary = 10111 4 0100 BCD = 0001 0111 5 0101 6 0110 7 0111 8 1000 9 1001

Page 49: EE 261 – Introduction to Logic Circuits Module #2 Page 1 EE 261 – Introduction to Logic Circuits Module #2 – Number Systems Topics A.Number System Formation

EE 261 – Introduction to Logic Circuits Module #2Page 49

Binary Codes

• BCD Addition

- If we are using BCD, traditional addition doesn’t work.

12 = correct answer in BCD is 20. Traditional addition only considers + 08 8-bit addition carry. In BCD we need to consider 4-bit

addition carry. 1A

- The solution is to add 6 to every sum greater than 9

12 = When a nibble addition results in “A” or greater, we add 6

08 1A + 6 20

Page 50: EE 261 – Introduction to Logic Circuits Module #2 Page 1 EE 261 – Introduction to Logic Circuits Module #2 – Number Systems Topics A.Number System Formation

EE 261 – Introduction to Logic Circuits Module #2Page 50

Binary Codes

• Gray Code

- There are applications where we want to count, but we only want one bit to transition each time we increment counts

- Reduce Power & Noise in Digital Electronics - Electromechanical devices

- Such a is called a "Gray Code"

ex) 3-bit Gray Code Decimal Binary Gray 0 000 000 1 001 001 2 010 011 3 011 010 4 100 110 5 101 111 6 110 101 7 111 100

Page 51: EE 261 – Introduction to Logic Circuits Module #2 Page 1 EE 261 – Introduction to Logic Circuits Module #2 – Number Systems Topics A.Number System Formation

EE 261 – Introduction to Logic Circuits Module #2Page 51

Binary Codes

• ASCII

- American Standard Code for Information Interchange

- English Alphanumeric characters are represented with a 7-bit code

- See Table 2-11 in text

ex) ‘A’ = $40

‘a’ = $61

Page 52: EE 261 – Introduction to Logic Circuits Module #2 Page 1 EE 261 – Introduction to Logic Circuits Module #2 – Number Systems Topics A.Number System Formation

EE 261 – Introduction to Logic Circuits Module #2Page 52

Binary Codes

• Parity Codes

- there are times when information can be corrupted during transmission

- we can include an "Error Checking" bit along with the original data

- this "Error Checking" bit contains additional information about the original data

- this can be used by the receiver to monitor whether an error in the data occurred

PARITY - the number of 1's in the information are counted, - the parity bit represents whether there are an EVEN or ODD number of 1's

EVEN PARITY = 0, if there are an EVEN number of 1's in the information = 1, otherwise

ODD PARITY = 0, if there are an ODD number of 1's in the information = 1, otherwise

Page 53: EE 261 – Introduction to Logic Circuits Module #2 Page 1 EE 261 – Introduction to Logic Circuits Module #2 – Number Systems Topics A.Number System Formation

EE 261 – Introduction to Logic Circuits Module #2Page 53

Binary Codes

• Parity Example

Information EVEN Parity ODD Parity 000 0 1 001 1 0 010 1 0 011 0 1 100 1 0 101 0 1 110 0 1 111 1 0

Page 54: EE 261 – Introduction to Logic Circuits Module #2 Page 1 EE 261 – Introduction to Logic Circuits Module #2 – Number Systems Topics A.Number System Formation

EE 261 – Introduction to Logic Circuits Module #2Page 54

Module Overview

• Topics

- # systems & bases- # system conversions - to & from decimal - to and from binary/oct/hex

- binary arithmetic- addition (carries)

- subtraction (borrows)

- negative #'s in binary - Signed Magnitude - 2's Complement - 1's Complement

- 2's complement arithmetic - complement & add - range & overflow - Codes - BCD, Gray, ASCII, Parity


Top Related