18
Topic 2: Number Systems Topic 2: Number Systems 1 What are the basic digital logic operations? What are the basic digital logic operations? What are number systems? What are number systems? How do we perform arithmetic in binary? How do we perform arithmetic in binary? Digital Logic Digital Logic Digital Logic considers two values: Digital Logic considers two values: – True True – False False 2 • Representation Representation – True may be abbreviated with T or 1 True may be abbreviated with T or 1 – False may be abbreviated with F or 0 False may be abbreviated with F or 0 Digital Logic Digital Logic Truth tables describe the behavior of Truth tables describe the behavior of logical operators logical operators Input(s) Output A not A 3 The not operator flips the value of its input The not operator flips the value of its input Input Values Output Values 0 1 Digital Logic Digital Logic And Operator And Operator – Takes two inputs Takes two inputs – Produces one output Produces one output Output is True if and only if both inputs are Output is True if and only if both inputs are 4 Output is True if and only if both inputs are Output is True if and only if both inputs are true true A B 0 0 0 1 1 0 1 1 A and B

Digital Logicpeople.ucalgary.ca/~bdstephe/231_W08/Topic2_Numbers_4up.pdf · ––False may be abbreviated with F or 0False may be abbreviated with F or 0 Digital Logic •• Truth

  • Upload
    others

  • View
    5

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Digital Logicpeople.ucalgary.ca/~bdstephe/231_W08/Topic2_Numbers_4up.pdf · ––False may be abbreviated with F or 0False may be abbreviated with F or 0 Digital Logic •• Truth

Topic 2: Number SystemsTopic 2: Number Systems

1

What are the basic digital logic operations? What are the basic digital logic operations? What are number systems?What are number systems?

How do we perform arithmetic in binary?How do we perform arithmetic in binary?

Digital LogicDigital Logic

•• Digital Logic considers two values:Digital Logic considers two values:–– TrueTrue–– FalseFalse

2

•• RepresentationRepresentation–– True may be abbreviated with T or 1True may be abbreviated with T or 1–– False may be abbreviated with F or 0False may be abbreviated with F or 0

Digital LogicDigital Logic

•• Truth tables describe the behavior of Truth tables describe the behavior of logical operatorslogical operators

Input(s) Output A not A

3

•• The not operator flips the value of its inputThe not operator flips the value of its input

InputValues

OutputValues

01

Digital LogicDigital Logic

•• And OperatorAnd Operator–– Takes two inputsTakes two inputs–– Produces one outputProduces one output–– Output is True if and only if both inputs are Output is True if and only if both inputs are

4

–– Output is True if and only if both inputs are Output is True if and only if both inputs are truetrue

A B

0 00 11 01 1

A and B

Page 2: Digital Logicpeople.ucalgary.ca/~bdstephe/231_W08/Topic2_Numbers_4up.pdf · ––False may be abbreviated with F or 0False may be abbreviated with F or 0 Digital Logic •• Truth

Digital LogicDigital Logic

•• Or OperatorOr Operator–– Takes two inputsTakes two inputs–– Produces one outputProduces one output–– Output is True if one input is true (or both Output is True if one input is true (or both

5

–– Output is True if one input is true (or both Output is True if one input is true (or both inputs are true)inputs are true)

A B

0 00 11 01 1

A or B

Digital LogicDigital Logic

•• Exclusive Or OperatorExclusive Or Operator–– Takes two inputsTakes two inputs–– Produces one outputProduces one output–– Output is True if exactly one input is trueOutput is True if exactly one input is true

6

–– Output is True if exactly one input is trueOutput is True if exactly one input is true

A B

0 00 11 01 1

A xor B

Digital LogicDigital Logic

•• When is not(A and B) true?When is not(A and B) true?

A B

0 0

A and B not (A and B)

7

•• We call this operation NANDWe call this operation NAND

0 00 11 01 1

Digital LogicDigital Logic

•• When is not(A or B) true?When is not(A or B) true?

A B

0 0

A or B not (A or B)

8

•• We call this operation NORWe call this operation NOR

0 00 11 01 1

Page 3: Digital Logicpeople.ucalgary.ca/~bdstephe/231_W08/Topic2_Numbers_4up.pdf · ––False may be abbreviated with F or 0False may be abbreviated with F or 0 Digital Logic •• Truth

Digital LogicDigital Logic

•• Example:Example:–– Construct a truth table for A and (B or not C): Construct a truth table for A and (B or not C):

9

Digital LogicDigital Logic

•• Digital logic is the basis for computation in Digital logic is the basis for computation in modern computersmodern computers–– Circuits can implement logical operationsCircuits can implement logical operations–– Arithmetic operations can be built up from Arithmetic operations can be built up from

10

–– Arithmetic operations can be built up from Arithmetic operations can be built up from logical operationslogical operations

–– Memory can be constructed by including Memory can be constructed by including feedback loops in the circuitsfeedback loops in the circuits

Logic GatesLogic Gates

•• And:And:

•• Or:Or:

11

•• XorXor::

•• NandNand::

•• Nor:Nor:

Logic GatesLogic Gates

•• Draw the logic gates to compute A and (B Draw the logic gates to compute A and (B or not C): or not C):

12

Page 4: Digital Logicpeople.ucalgary.ca/~bdstephe/231_W08/Topic2_Numbers_4up.pdf · ––False may be abbreviated with F or 0False may be abbreviated with F or 0 Digital Logic •• Truth

Logic GatesLogic Gates

13

What is Decimal?What is Decimal?

•• Think about the way we normally count?Think about the way we normally count?–– How many unique symbols are there?How many unique symbols are there?

14

Representing Larger NumbersRepresenting Larger Numbers

•• We only have 10 distinct symbolsWe only have 10 distinct symbols•• Positional representation allows us to Positional representation allows us to

represent larger numbersrepresent larger numbers–– What does 24 really mean?What does 24 really mean?

15

–– What does 24 really mean?What does 24 really mean?

–– What does 3709 really mean?What does 3709 really mean?

What is Binary?What is Binary?

•• A number system with only two distinct A number system with only two distinct symbolssymbols–– Normally denoted by 0 and 1Normally denoted by 0 and 1–– Used extensively in digital electronicsUsed extensively in digital electronics

16

–– Used extensively in digital electronicsUsed extensively in digital electronics–– Uses the same positional rules as base 10Uses the same positional rules as base 10

•• What does 10110 mean in base 10?What does 10110 mean in base 10?

•• What does 10110 mean in base 2?What does 10110 mean in base 2?

Page 5: Digital Logicpeople.ucalgary.ca/~bdstephe/231_W08/Topic2_Numbers_4up.pdf · ––False may be abbreviated with F or 0False may be abbreviated with F or 0 Digital Logic •• Truth

What is Binary?What is Binary?

•• More examples:More examples:–– Convert 1111Convert 111122 to base 10to base 10

17

–– Convert 100010Convert 10001022 to base 10to base 10

–– Convert 0Convert 022 to base 10to base 10

Converting Between BasesConverting Between Bases

•• How do we convert from Binary to How do we convert from Binary to Decimal?Decimal?–– Use positional representationUse positional representation

•• How do we convert from Decimal to How do we convert from Decimal to

18

•• How do we convert from Decimal to How do we convert from Decimal to Binary?Binary?

The Division MethodThe Division Method

•• Allows us to convert from Decimal to Allows us to convert from Decimal to BinaryBinary–– Let N represent the number to convertLet N represent the number to convert–– Set Q equal to NSet Q equal to N

19

–– Set Q equal to NSet Q equal to N–– RepeatRepeat

•• Divide Q by 2, recording the Quotient, Q, and the Divide Q by 2, recording the Quotient, Q, and the remainder, Rremainder, R

–– Until Q is 0Until Q is 0–– Read the remainders from bottom to topRead the remainders from bottom to top

The Division MethodThe Division Method

•• Example:Example:–– Convert 12Convert 121010 to base 2 using the division to base 2 using the division

methodmethod

20

Page 6: Digital Logicpeople.ucalgary.ca/~bdstephe/231_W08/Topic2_Numbers_4up.pdf · ––False may be abbreviated with F or 0False may be abbreviated with F or 0 Digital Logic •• Truth

The Division MethodThe Division Method

•• Example:Example:–– Convert 191Convert 1911010 to binary using the division to binary using the division

methodmethod

21

Other BasesOther Bases

•• A number system can have any baseA number system can have any base–– Decimal: Base 10Decimal: Base 10–– Binary: Base 2Binary: Base 2–– Octal: Base 8Octal: Base 8

22

–– Octal: Base 8Octal: Base 8–– Hexadecimal: Base 16Hexadecimal: Base 16–– VigesimalVigesimal: Base 20: Base 20–– Or any other number we choose…Or any other number we choose…

HexadecimalHexadecimal

•• Base 16 Base 16 –– commonly used by computer commonly used by computer scientistsscientists–– Requires 16 distinct symbolsRequires 16 distinct symbols–– First 10 are 0 .. 9First 10 are 0 .. 9

23

–– First 10 are 0 .. 9First 10 are 0 .. 9–– Remainder are letters A, B, C, D, E, FRemainder are letters A, B, C, D, E, F–– Convert 10Convert 101616 to base 10:to base 10:

–– Convert 0xD5E to base 10:Convert 0xD5E to base 10:

HexadecimalHexadecimal

•• Example:Example:–– Convert 222Convert 2221010 to Hexadecimalto Hexadecimal

24

Page 7: Digital Logicpeople.ucalgary.ca/~bdstephe/231_W08/Topic2_Numbers_4up.pdf · ––False may be abbreviated with F or 0False may be abbreviated with F or 0 Digital Logic •• Truth

Arbitrary Base ConversionsArbitrary Base Conversions

•• How do we convert NHow do we convert NAA to base B?to base B?–– Convert NConvert NAA to base 10to base 10–– Convert from base 10 to base BConvert from base 10 to base B–– Example: Convert 452Example: Convert 452 to base 12to base 12

25

–– Example: Convert 452Example: Convert 45277 to base 12to base 12

Arbitrary Base ConversionsArbitrary Base Conversions

•• Another Example:Another Example:–– Convert 0xFF to base 6Convert 0xFF to base 6

26

Base 2Base 20011

10101111100100101101110110111111

Base 8Base 80011223344556677

Base 10Base 100011223344556677

Base 16Base 160011223344556677

27

10001000100110011010101010111011110011001101110111101110111111111000010000

101011111212131314141515161617172020

8899

1010111112121313141415151616

8899AABBCCDDEEFF1010

GroupingGrouping

•• Faster arbitrary base conversions are Faster arbitrary base conversions are possible in some casespossible in some cases–– Let A and B represented the basesLet A and B represented the bases–– If A = If A = BBnn or B = Aor B = Ann for some positive integer, n, for some positive integer, n,

28

–– If A = If A = BBnn or B = Aor B = Ann for some positive integer, n, for some positive integer, n, then we can convert using groups of n digitsthen we can convert using groups of n digits

•• Converting from a larger base to a smaller base Converting from a larger base to a smaller base means that we generate n digits of output for each means that we generate n digits of output for each digit of inputdigit of input

•• Converting from a smaller base to a larger base Converting from a smaller base to a larger base means that we use n digits of input to create on means that we use n digits of input to create on digit of outputdigit of output

Page 8: Digital Logicpeople.ucalgary.ca/~bdstephe/231_W08/Topic2_Numbers_4up.pdf · ––False may be abbreviated with F or 0False may be abbreviated with F or 0 Digital Logic •• Truth

GroupingGrouping

•• Example:Example:–– Convert 315Convert 31588 to Binaryto Binary

29

GroupingGrouping

•• Example:Example:–– Convert 11302Convert 1130244 to base 16to base 16

30

GroupingGrouping

•• Example:Example:–– Convert 354Convert 35488 to Hexadecimalto Hexadecimal

31

Hexadecimal ShorthandHexadecimal Shorthand

•• Writing long sequences of 0 and 1 is Writing long sequences of 0 and 1 is cumbersome and error pronecumbersome and error prone–– Computer Scientist frequently use Computer Scientist frequently use

hexadecimal to represent sequences of bitshexadecimal to represent sequences of bits

32

hexadecimal to represent sequences of bitshexadecimal to represent sequences of bits–– Memorize your hexadecimal, binary and Memorize your hexadecimal, binary and

decimal conversions for 0 to 15decimal conversions for 0 to 15

Page 9: Digital Logicpeople.ucalgary.ca/~bdstephe/231_W08/Topic2_Numbers_4up.pdf · ––False may be abbreviated with F or 0False may be abbreviated with F or 0 Digital Logic •• Truth

Arbitrary Base ConversionsArbitrary Base Conversions

•• Why do computer scientists keep on Why do computer scientists keep on confusing Halloween and Christmas?confusing Halloween and Christmas?

33

FractionsFractions

•• What does 3.1415What does 3.14151010 really mean?really mean?

34

•• What does 101.101What does 101.10122 really mean?really mean?

Conversions Involving FractionsConversions Involving Fractions

•• Convert 4.125Convert 4.1251010 to Binaryto Binary–– Separate the integer and fractional portionsSeparate the integer and fractional portions

•• Use the division method on the integer portionUse the division method on the integer portion•• Use multiplication method on fractional portionUse multiplication method on fractional portion

35

•• Use multiplication method on fractional portionUse multiplication method on fractional portion

Conversions Involving FractionsConversions Involving Fractions

•• Convert 3.1415Convert 3.14151010 to Hexadecimal:to Hexadecimal:

36

Page 10: Digital Logicpeople.ucalgary.ca/~bdstephe/231_W08/Topic2_Numbers_4up.pdf · ––False may be abbreviated with F or 0False may be abbreviated with F or 0 Digital Logic •• Truth

Number SystemsNumber Systems

•• Base 10 is natural because we learned it Base 10 is natural because we learned it firstfirst–– Nothing special about it beyond thatNothing special about it beyond that–– Offers same expressive power as other basesOffers same expressive power as other bases

37

–– Offers same expressive power as other basesOffers same expressive power as other bases

•• Binary and bases that are powers of 2 are Binary and bases that are powers of 2 are frequently used in computer sciencefrequently used in computer science–– Digital electronics are inherently binaryDigital electronics are inherently binary

Representing NumbersRepresenting Numbers

•• Computers are inherently binaryComputers are inherently binary–– Everything is a 1 or a 0Everything is a 1 or a 0–– Size LimitsSize Limits

•• Computers don’t have infinite memoryComputers don’t have infinite memory

38

•• Computers don’t have infinite memoryComputers don’t have infinite memory•• Can only represent numbers within a confined Can only represent numbers within a confined

rangerange

–– Numbers are represented in binaryNumbers are represented in binary•• Natural for positive numbersNatural for positive numbers•• How do we represent a negative number?How do we represent a negative number?

Size LimitsSize Limits

•• Common sizes for numbers in a computerCommon sizes for numbers in a computer–– 8 bits (referred to as a byte)8 bits (referred to as a byte)

–– 16 bits (often referred to as a half16 bits (often referred to as a half--word)word)

39

–– 16 bits (often referred to as a half16 bits (often referred to as a half--word)word)

–– 32 bits (often referred to as a word)32 bits (often referred to as a word)

–– 64 bits (often referred to as a double word)64 bits (often referred to as a double word)

Negative NumbersNegative Numbers

•• Everything is a 1 or a 0Everything is a 1 or a 0–– Can’t use a negative sign directlyCan’t use a negative sign directly–– Must encode as either a 1 or a 0Must encode as either a 1 or a 0–– Several encoding choices are availableSeveral encoding choices are available

40

–– Several encoding choices are availableSeveral encoding choices are available•• Advantages and disadvantages of each encodingAdvantages and disadvantages of each encoding

Page 11: Digital Logicpeople.ucalgary.ca/~bdstephe/231_W08/Topic2_Numbers_4up.pdf · ––False may be abbreviated with F or 0False may be abbreviated with F or 0 Digital Logic •• Truth

Signed MagnitudeSigned Magnitude

•• Signed MagnitudeSigned Magnitude–– Decide that the left most bit in a unit Decide that the left most bit in a unit

represents the signrepresents the sign–– Decide that 0 represents positive and 1 Decide that 0 represents positive and 1

41

–– Decide that 0 represents positive and 1 Decide that 0 represents positive and 1 represents negativerepresents negative

–– Remainder of the bits represent the Remainder of the bits represent the magnitude in positional representationmagnitude in positional representation

Signed MagnitudeSigned Magnitude

•• How do we represent 100How do we represent 1001010 as a byte?as a byte?

42

•• How do we represent How do we represent --1001001010 as a byte?as a byte?

Signed MagnitudeSigned Magnitude

•• What is the range of integers we can What is the range of integers we can represent using signed magnituderepresent using signed magnitude–– in a byte?in a byte?

43

–– in a half word?in a half word?

–– in a word?in a word?

–– in a double word?in a double word?

Signed MagnitudeSigned Magnitude

•• How do we know if a number is positive or How do we know if a number is positive or negative?negative?

•• How do we negate a number using signed How do we negate a number using signed

44

•• How do we negate a number using signed How do we negate a number using signed magnitude?magnitude?

•• What is a disadvantage of signed What is a disadvantage of signed magnitude?magnitude?

Page 12: Digital Logicpeople.ucalgary.ca/~bdstephe/231_W08/Topic2_Numbers_4up.pdf · ––False may be abbreviated with F or 0False may be abbreviated with F or 0 Digital Logic •• Truth

One’s ComplementOne’s Complement

•• Another representation for negative Another representation for negative integersintegers–– Positive integers as usualPositive integers as usual–– Negative integers are formed by taking the Negative integers are formed by taking the

45

–– Negative integers are formed by taking the Negative integers are formed by taking the positive integer with the same magnitude and positive integer with the same magnitude and flipping every bitflipping every bit

One’s ComplementOne’s Complement

•• How do we represent 100How do we represent 1001010 as a byte?as a byte?

46

•• How do we represent How do we represent --1001001010 as a byte?as a byte?

One’s ComplementOne’s Complement

•• What is the range of integers we can What is the range of integers we can represent using one’s complement?represent using one’s complement?–– in a byte?in a byte?

47

–– in a half word?in a half word?

–– in a word?in a word?

–– in a double word?in a double word?

One’s ComplementOne’s Complement

•• How do we know if a number is positive or How do we know if a number is positive or negative?negative?

•• How do we negate a number using one’s How do we negate a number using one’s

48

•• How do we negate a number using one’s How do we negate a number using one’s complement?complement?

•• What is a disadvantage of one’s What is a disadvantage of one’s complement?complement?

Page 13: Digital Logicpeople.ucalgary.ca/~bdstephe/231_W08/Topic2_Numbers_4up.pdf · ––False may be abbreviated with F or 0False may be abbreviated with F or 0 Digital Logic •• Truth

Two’s ComplementTwo’s Complement

•• Another representation for negative Another representation for negative integersintegers–– Positive integers as usualPositive integers as usual–– Negative integers are formed by taking the Negative integers are formed by taking the

49

–– Negative integers are formed by taking the Negative integers are formed by taking the positive integer with the same magnitude and positive integer with the same magnitude and flipping every bit, then adding oneflipping every bit, then adding one

Two’s ComplementTwo’s Complement

•• How do we represent 100How do we represent 1001010 as a byte?as a byte?

50

•• How do we represent How do we represent --1001001010 as a byte?as a byte?

Two’s ComplementTwo’s Complement

•• What is the range of integers we can What is the range of integers we can represent using two’s complement?represent using two’s complement?–– in a byte?in a byte?

51

–– in a half word?in a half word?

–– in a word?in a word?

–– in a double word?in a double word?

Two’s ComplementTwo’s Complement

•• How do we know if a number is positive or How do we know if a number is positive or negative?negative?

•• How do we negate a number using two’s How do we negate a number using two’s

52

•• How do we negate a number using two’s How do we negate a number using two’s complement?complement?

•• What is the advantage of two’s What is the advantage of two’s complement?complement?

Page 14: Digital Logicpeople.ucalgary.ca/~bdstephe/231_W08/Topic2_Numbers_4up.pdf · ––False may be abbreviated with F or 0False may be abbreviated with F or 0 Digital Logic •• Truth

Representing Negative NumbersRepresenting Negative Numbers

•• In all three systemsIn all three systems–– Positive numbers are represented using Positive numbers are represented using

positional representationpositional representation–– A number is negative if its left most bit is oneA number is negative if its left most bit is one

53

–– A number is negative if its left most bit is oneA number is negative if its left most bit is one

•• The same sequence of bits represents a The same sequence of bits represents a different negative integer in each systemdifferent negative integer in each system

AdditionAddition

•• How do we add in base 2?How do we add in base 2?

00 00+0+0 +1+1

54

11 11+0+0 +1+1

Logic GatesLogic Gates

55

AdditionAddition

•• Adding larger binary numbersAdding larger binary numbers

0101010101010101+00001111+00001111

56

+00001111+00001111

0101010101010101+00100101+00100101

Page 15: Digital Logicpeople.ucalgary.ca/~bdstephe/231_W08/Topic2_Numbers_4up.pdf · ––False may be abbreviated with F or 0False may be abbreviated with F or 0 Digital Logic •• Truth

Logic GatesLogic Gates

57

Signed Magnitude AdditionSigned Magnitude Addition

•• Similar to addition in base 10Similar to addition in base 10–– If both operands have the same signIf both operands have the same sign

•• Add the magnitudesAdd the magnitudes•• Result has same sign as operandsResult has same sign as operands

58

•• Result has same sign as operandsResult has same sign as operands

–– If operands have different signsIf operands have different signs•• Subtract the smaller operand from the larger Subtract the smaller operand from the larger

operandoperand•• Result has the same sign as the larger operandResult has the same sign as the larger operand

One’s Complement AdditionOne’s Complement Addition

•• Addition is the same for any combination Addition is the same for any combination of positive and negative integersof positive and negative integers–– Add the bits together with carries handled in Add the bits together with carries handled in

the usual waythe usual way

59

the usual waythe usual way–– If there is a carry out of the left most position If there is a carry out of the left most position

perform an ‘endperform an ‘end--around’ carry and continue around’ carry and continue addingadding

One’s Complement AdditionOne’s Complement Addition

•• Examples:Examples:

1001001010010010 1001001010010010+01100111+01100111 +11101111+11101111

60

+01100111+01100111 +11101111+11101111

Page 16: Digital Logicpeople.ucalgary.ca/~bdstephe/231_W08/Topic2_Numbers_4up.pdf · ––False may be abbreviated with F or 0False may be abbreviated with F or 0 Digital Logic •• Truth

Two’s Complement AdditionTwo’s Complement Addition

•• Addition is the same for any combination Addition is the same for any combination of positive and negative numbersof positive and negative numbers–– Add the bits together with carries handled in Add the bits together with carries handled in

the usual waythe usual way

61

the usual waythe usual way–– Discard any carry out from the left most bitDiscard any carry out from the left most bit

Two’s Complement AdditionTwo’s Complement Addition

•• Examples:Examples:

1001001010010010 1001001010010010+11101111+11101111 +10101111+10101111

62

+11101111+11101111 +10101111+10101111

OverflowOverflow

•• What happens when What happens when we try to increment the we try to increment the counter beyond 9999?counter beyond 9999?

63

•• Why does overflow Why does overflow occur in a computer?occur in a computer?

Types of OverflowTypes of Overflow

•• Any sequence of bits can be considered Any sequence of bits can be considered an unsigned numberan unsigned number–– Use positional representationUse positional representation

•• Any sequence of bits can be considered a Any sequence of bits can be considered a

64

•• Any sequence of bits can be considered a Any sequence of bits can be considered a signed numbersigned number–– If the left most bit is 0, the number is positiveIf the left most bit is 0, the number is positive

•• Use positional representationUse positional representation

–– If the left most bit is 1, the number is negativeIf the left most bit is 1, the number is negative•• Must know what representation is being usedMust know what representation is being used

Page 17: Digital Logicpeople.ucalgary.ca/~bdstephe/231_W08/Topic2_Numbers_4up.pdf · ––False may be abbreviated with F or 0False may be abbreviated with F or 0 Digital Logic •• Truth

Unsigned OverflowUnsigned Overflow

•• Assume all numbers are unsignedAssume all numbers are unsigned

0101010101010101 1010000010100000

+00001111+00001111 +01111111+01111111

65

+00001111+00001111 +01111111+011111110110010001100100

0101010101010101 1010000010100000+01010101+01010101 +11111111+11111111

1010101010101010

Signed OverflowSigned Overflow

•• Assume all numbers are 2’s complementAssume all numbers are 2’s complement

0101010101010101 1010000010100000

+00001111+00001111 +01111111+01111111

66

+00001111+00001111 +01111111+011111110110010001100100

0101010101010101 1010000010100000+01010101+01010101 +11111111+11111111

1010101010101010

OverflowOverflow

•• Overflow can be signed or unsignedOverflow can be signed or unsigned–– Unsigned overflow occurs when we need Unsigned overflow occurs when we need

more bits to represent the answer than we more bits to represent the answer than we havehave

67

havehave–– Signed overflow occurs when we have two Signed overflow occurs when we have two

numbers in numbers in nn bits with the same sign and get bits with the same sign and get a result in n bits with the opposite signa result in n bits with the opposite sign

•• Signed overflow never occurs when the input Signed overflow never occurs when the input numbers have opposite signsnumbers have opposite signs

PracticePractice

68

Page 18: Digital Logicpeople.ucalgary.ca/~bdstephe/231_W08/Topic2_Numbers_4up.pdf · ––False may be abbreviated with F or 0False may be abbreviated with F or 0 Digital Logic •• Truth

Finishing UpFinishing Up

•• We have seen:We have seen:–– Basics of LogicBasics of Logic

•• Truth tables and logic gatesTruth tables and logic gates

–– Number SystemsNumber Systems

69

–– Number SystemsNumber Systems•• Binary and hexadecimalBinary and hexadecimal

–– Representing numbers in a computerRepresenting numbers in a computer•• Positional representationPositional representation•• Signed magnitude, one’s complement and two’s Signed magnitude, one’s complement and two’s

complementcomplement

Finishing UpFinishing Up

•• We have seen:We have seen:–– Addition in binaryAddition in binary

•• Positive numbersPositive numbers•• NegativeNegative

70

•• NegativeNegative•• OverflowOverflow