+ All Categories
Home > Documents > 1.Number Systems

1.Number Systems

Date post: 14-Apr-2018
Category:
Upload: chai-kueh-khun
View: 213 times
Download: 0 times
Share this document with a friend

of 48

Transcript
  • 7/27/2019 1.Number Systems

    1/48

    Number Systems

  • 7/27/2019 1.Number Systems

    2/48

    HET202 Digital Electronics Design 2

    Analogue vs Digital

    Analogue Continuous range of values

    Precision limited by noise

    Digital Discrete range of values

    (usually 2) but Precision limited by number ofbits

    t

    t

  • 7/27/2019 1.Number Systems

    3/48

    HET202 Digital Electronics Design 3

    Analogue vs Digital The real world is analogue (if you ignore

    Quantum effects!).

    It is common to translate data from analogue todigital for processing and back to analogue for

    output. Why bother?

    Advances in integrated circuits (ICs) has made thecomplex processing of digital data very inexpensive.

    Digital circuits are inherently more noise resistant.

    AnalogueWorld

    AnalogueWorld

    Digital

    Processing

    AtoD DtoA

  • 7/27/2019 1.Number Systems

    4/48

    HET202 Digital Electronics Design 4

    Why Boolean? It is convenient in electrical systems to use a

    two-value system to represent values true/false, on/off, yes/no, 1/0. Two voltage or current levels can be used.

    Easier to process and distribute reliably.

    Dont think of them as numbers (even though weoften represent them as 0/1 for brevity).

    The Need for Binary Numbers.

    Multi-value quantities need to be represented inthe digital system. We therefore need numbersmade up from the simpler two value system torepresent a rangeof discrete values.

  • 7/27/2019 1.Number Systems

    5/48

    HET202 Digital Electronics Design 5

    Combinational vs. Sequential Two categories of digital circuits:

    Combinational: The output is purely a function of the

    current input.

    Sequential:

    The output is dependent upon what has

    happened previously and possibly thecurrent inputs.

  • 7/27/2019 1.Number Systems

    6/48

    HET202 Digital Electronics Design 6

    Combinational Circuits Output values only depend upon the

    current input values (ignoringpropagation effects speed)

    System has no state (memory of

    what has happened before)

    Z=f(W,X,Y)

    W

    X

    Y

    Z

  • 7/27/2019 1.Number Systems

    7/48

    HET202 Digital Electronics Design 7

    Sequential Circuits Output depends on present and past

    inputs. Circuit has state (held in flip-flops).

    Example: circuit for elevator call button.

    Has to remember the brief button pressuntil the elevator arrives.

    SequentialCircuit

    (internal state)

    Call elevator(push button)

    Momentary value

    Elevator calledPersistent value

  • 7/27/2019 1.Number Systems

    8/48

    HET202 Digital Electronics Design 8

    Positional Number Systems

    1024.339

    3 x 10-1

    3 x 10-2

    9 x 10-3

    4 x 100

    2 x 101

    0 x 102

    1 x 103

    decimal point

    Base 10 weightings are powers of 10

  • 7/27/2019 1.Number Systems

    9/48

    HET202 Digital Electronics Design 9

    Unsigned Binary Numbers

    1001.101

    1 x 2-1 = 0.500

    0 x 2-2 = 0.000

    1 x 2-3 = 0.125

    1 x 20 = 1.000

    0 x 21 = 0.000

    0 x 22 = 0.000

    1 x 23 = 8.000

    binary point

    9.625

    Binary weightings are powers of 2

    Each bit of thenumber may be

    represented bya Boolean value.

  • 7/27/2019 1.Number Systems

    10/48

    HET202 Digital Electronics Design 10

    Decimal to BinaryGenerate each digit bysuccessive division or

    multiplication.

    There is no guaranteethe fraction will be finite!

    Number = 36.375

    Base= 2

    Decimal

    Number

    Binary

    Digits

    Converted

    Number

    0 0 0100100.0110

    0.5 1 0100100.011

    0.75 1 0100100.01

    0.375 0 0100100.0

    36 0 0100100

    18 0 0100109 1 01001

    4 0 0100

    2 0 010

    1 1 01

    0 0 0

    Fractional part Multiplication by base (2)

    Whole number part Division by base (2)

    Fractionpart

    Whole

    part

  • 7/27/2019 1.Number Systems

    11/48

    HET202 Digital Electronics Design 11

    Decimal to Base-7Number = 45.75

    Base= 7

    Decimal

    Number

    Binary

    Digits

    Converted

    Number

    0.25 1 063.5151

    0.75 5 063.515

    0.25 1 063.51

    0.75 5 063.545 3 063

    6 6 06

    0 0 0

    Fractional part -

    Multiplication by base (7)

    Whole number part -Division by base (7)

  • 7/27/2019 1.Number Systems

    12/48

    HET202 Digital Electronics Design 12

    Binary Addition

    0 + 0 = 0

    0 + 1 = 1

    1 + 0 = 1

    1 + 1 = 0 carry 1

    Easy huh?

  • 7/27/2019 1.Number Systems

    13/48

    HET202 Digital Electronics Design 13

    Binary Addition

    11 1 1

    1 1 1 01 0 1 1

    1 1 0 11 0 0 0

    1 0 1 10 1 0 0

    Carry out of8-bit number

    Carry out ofeach column

    190+141=331

    1

    1

  • 7/27/2019 1.Number Systems

    14/48

    HET202 Digital Electronics Design 14

    Binary Subtraction

    2 2 22 2

    0 1 0 11 1 1 01 1 1 00 0 1 0

    0 1 1 11 0 1 1

    Borrow in fromleft column

    11111

    Borrow outBoth rowssubtracted

    229-46=183

    A borrow-out of 1 fromthis column becomes a borrow-in

    of 2 in this column

  • 7/27/2019 1.Number Systems

    15/48

    HET202 Digital Electronics Design 15

    Exercise Convert to 8-bit binary and do the

    arithmetic operation: 120 + 54

    224 134

    112 89

    Convert back to decimal and check the

    results.

  • 7/27/2019 1.Number Systems

    16/48

    HET202 Digital Electronics Design 16

    Exercise Working120 + 54 224 134

    112 89

  • 7/27/2019 1.Number Systems

    17/48

    HET202 Digital Electronics Design 17

    Exercise Solution120 + 54

    120 = 01111000254 = 001101102

    101011102

    = 174

    224 134

    224 = 111000002134 = 100001102

    010110102

    = 90

    112 89

    112 = 01110000289 = 010110012000101112

    = 23

    *

  • 7/27/2019 1.Number Systems

    18/48

    HET202 Digital Electronics Design 18

    Exercises Some exercises to highlight overflow

    (carry/borrow)

  • 7/27/2019 1.Number Systems

    19/48

    HET202 Digital Electronics Design 19

    Binary Number Circle

    4-bitbinary

    number circle

    0

    4

    8

    12

    2

    6

    14

    10

    1

    5

    9

    13 3

    7

    15

    11

    11 - 1 = 10

    In real hardware there isa fixed number of bitsavailable. We oftenignore leading zeroes butthey are still there!

    Example:

    If we only use 4 bits thenthe binary counting

    sequence wraps aroundat 150.

  • 7/27/2019 1.Number Systems

    20/48

    HET202 Digital Electronics Design 20

    Binary Number Circle

    4-bitbinary

    number circle

    0

    4

    8

    12

    2

    6

    14

    10

    1

    5

    9

    13 3

    7

    15

    11

    8 - 14 = 10

    Subtracting across theboundary still works ifyou think of the result asthe distance on thenumber circle.

    (Modulo arithmetic ignore the borrow/carry)

    8 1000

    - 14 - 1110

    10 (1)1010

  • 7/27/2019 1.Number Systems

    21/48

    HET202 Digital Electronics Design 21

    Representing ve Numbers Several choices for notation

    Sign + Magnitude notation (discussed) 1s Complement (not discussed)

    2s Complement notation (discussed)

    Various excess codes (not discussed)

  • 7/27/2019 1.Number Systems

    22/48

    HET202 Digital Electronics Design 22

    Signed Numbers

    Sign+Magnitude Notation

    Sign Bit Magnitude

    Simple binary number0+ve

    1 -ve

    Problems?

    +0

    -0

    0000

    1000

  • 7/27/2019 1.Number Systems

    23/48

    HET202 Digital Electronics Design 23

    Signed Numbers

    Sign+MagnitudeArithmetic

    Difficult to do have to work out what operation toperform

    5 + -6 actually calculate -(6 - 5) i.e. exchange the

    operands and do subtraction!-5 + -6 actually calculate -(5 + 6) i.e. negate the

    addition of the negated numbers!

    Required action depends the signs of the numbers andon which has the larger magnitude. Natural for us a

    bit hard for the computer since the only way it can

    work out the bigger number is to do a subtraction!

  • 7/27/2019 1.Number Systems

    24/48

    HET202 Digital Electronics Design 24

    Sign+Magnitude ExamplesValue 4-bit sign + magnitude 8-bit sign + magnitude

    +7 0111 00000111

    +6 0110 00000110

    ... ... ...

    +1 0001 00000001+0 0000 00000000

    -0 1000 10000000

    -1 1001 10000001

    -2 1010 10000010

    ... ... ...

    -7 1111 10000111

  • 7/27/2019 1.Number Systems

    25/48

    HET202 Digital Electronics Design 25

    Signed Numbers 2s ComplementAs for straight binary numbers but with

    the weighting of the most significant bitbeing negative.

    Example:

    4 bit weights are -8,4,2,1 8 bit weights are -128,64,32,16,8,4,2,1

    Need to know how many bits are being

    used to work out the value of thenumber dont omit leading zeroes.

  • 7/27/2019 1.Number Systems

    26/48

    HET202 Digital Electronics Design 26

    Signed Numbers 2s Complement

    1001.101

    1 x 2-1

    = 0.5000 x 2-2 = 0.000

    1 x 2-3 = 0.125

    1 x 20 = 1.000

    0 x 21 = 0.000

    0 x 22 = 0.000-1 x 23 =-8.000

    binary point

    -6.375

    Sign

    Bit

  • 7/27/2019 1.Number Systems

    27/48

    HET202 Digital Electronics Design 27

    2s Complement ExamplesNumber

    4-bit 2'scomplement

    8-bit 2'scomplement

    +7 0111 00000111+6 0110 00000110

    ... ... ...

    +1 0001 00000001

    0 0000 00000000

    -1 1111 11111111

    -2 1110 11111110

    ... ... ...

    -6 1010 11111010

    -7 1001 11111001

    -8 1000 11111000

  • 7/27/2019 1.Number Systems

    28/48

    HET202 Digital Electronics Design 28

    What is OVERFLOW? When the word length is n bits, we say

    that an overflowhas occurred if thecorrect representation of the sum(including sign) requires more that n

    bits.

  • 7/27/2019 1.Number Systems

    29/48

    HET202 Digital Electronics Design 29

    Interpreting valuesas unsigned binary

    Interpreting values

    as 2s complement

    Binary

    1011

    0011

    (0)1110

    V=0,C=0

    0110

    0110(0)1100

    V=1,C=0

    Binary

    1011

    1101

    (1)1000

    V=0,C=1

    1011

    1010(1)0101

    V=1,C=1

    Signed

    Value

    -5

    3

    -2

    6

    6-4

    Wrong

    Unsigned

    Value

    11

    3

    14

    6

    612

    Signed

    Value

    -5

    -3

    -8

    -5

    -65

    Wrong

    Unsigned

    Value

    11

    13

    8

    Wrong

    11

    105

    Wrong

    Examples

  • 7/27/2019 1.Number Systems

    30/48

    HET202 Digital Electronics Design 30

    Why Use 2s Complement? Addition and subtraction use the same rules as

    unsigned binary.

    Same hardware may be used for both. Hardware may be shared.

    Carry (C) is used for unsigned, Overflow (V) for signed

    Carry

    Overflow

    Carry

    Overflow

    OP

    SignedNumbers

    SignedNumber

    OP

    UnsignedNumbers

    UnsignedNumber

    The samehardware

    Condition code

    register (CCR)

  • 7/27/2019 1.Number Systems

    31/48

    HET202 Digital Electronics Design 31

    2s Complement To negate a number in 2s

    complement it is necessary tosubtract it from zero.

    A short-hand for this is:

    Complement the number (flip each bit).

    Add 1 to the result (discard any carry).

  • 7/27/2019 1.Number Systems

    32/48

    HET202 Digital Electronics Design 32

    2s Complement

    Generate (-7) in 8 bits

    7 => 000001112

    Subtract from zero

    0000 00002 0

    -0000 01112 7

    1111 10012 -7

    Generate (-7) in 8 bits

    7 => 000001112

    Complement & add 1

    (discard any carry)

    0000 01112 7

    1111 10002 ~7

    +0000 00012 +1

    1111 10012 -7

  • 7/27/2019 1.Number Systems

    33/48

    HET202 Digital Electronics Design 33

    Widening 2s Complement Numbers Need to sign-extend the number to

    maintain the signed value.

    1 0 0 1

    1 1 1 1 1 0 0 1

    0 1 0 1

    0 0 0 0 0 1 0 1

    (-8)+1= -7

    (-128)+64+32+16+8+1= -7

    4+1= 5

    4+1= 5

  • 7/27/2019 1.Number Systems

    34/48

    HET202 Digital Electronics Design 34

    Number LinesNumber Lines for 8-bit Signed & Unsigned Numbers

    0 +127 +128 +255

    0 +127-128 -1

    Unsigned Range

    Signed Range (2s complement)

    10000000 11111111 00000000 01111111 10000000 11111111

    Which number is larger?00011101 0111010011010111 0001110111010111 10000100

    AAA

    BBB

  • 7/27/2019 1.Number Systems

    35/48

    HET202 Digital Electronics Design 35

    Number Ranges8-bit 2s complement

    -128 +127

    16-bit 2s complement

    -32,768 +32,767

    8-bit unsigned

    0 +255

    16-bit unsigned

    0 +65535

  • 7/27/2019 1.Number Systems

    36/48

    HET202 Digital Electronics Design 36

    Exercises Convert to 8-bit 2s complement and do

    the operation 120 + 54

    112 89 straight subtraction

    112 + (89) do complement & add

  • 7/27/2019 1.Number Systems

    37/48

    HET202 Digital Electronics Design 37

    Exercise Working120 + 54 112 89

  • 7/27/2019 1.Number Systems

    38/48

    HET202 Digital Electronics Design 38

    Exercise Solution120 + 54

    120 = 01111000254 = 001101102

    101011102

    = 82

    (overflow!)

    *112 89

    112 = 01110000289 = 010110012

    000101112

    = 23

  • 7/27/2019 1.Number Systems

    39/48

    HET202 Digital Electronics Design 39

    Exercise Working

    OR

    112 89

    = 112 + (~89) + 1

    112 89 = 112 + (89)

  • 7/27/2019 1.Number Systems

    40/48

    HET202 Digital Electronics Design 40

    Exercise Solution

    OR

    112 89

    112 = 01110000289 = 010110012~89 = 101001102

    *

    = 112 + (~89) + 1

    112 = 011100002

    ~89 = 101001102+1 = 000000012000101112

    = 23

    112 89

    112 = 011100002

    89 = 010110012~89 = 101001102-89 = 101001112

    = 112 + (89)

    112 = 011100002-89 = 101001112

    000101112= 23

  • 7/27/2019 1.Number Systems

    41/48

    HET202 Digital Electronics Design 41

    Binary Coded Decimal (BCD) BCD uses decimal arithmetic.

    We are simply using a 4-bit code torepresent each decimal digit.

  • 7/27/2019 1.Number Systems

    42/48

    HET202 Digital Electronics Design 42

    Binary Coded Decimal (BCD)

    0011,1001.0110

    decimal point

    6 x 10-1 = .6

    9 x 10 0 = 9.0

    3 x 10 1 = 30.0

    39.6

    Each group of 4-digits represents a decimal digit

  • 7/27/2019 1.Number Systems

    43/48

    HET202 Digital Electronics Design 43

    Binary Coded Decimal Disadvantages (relative to binary):

    Less efficient in storage e.g. 4 bytes allows

    99,999,999 versus 4,292,967,296 in binary.Arithmetic is more complex (in particular

    multiplication and division).

    Advantages (relative to binary): Input/Output conversion is much easier i.e.computer human readable.

    Less conversion errors i.e. decimal fractions are

    converted exactly (within precision). This isimportant in finance. Example - try $6.30 in BCD& binary.

  • 7/27/2019 1.Number Systems

    44/48

    HET202 Digital Electronics Design 44

    Other Codes Other codes may be used that are attractive

    in a particular application. Example:

    What problems might the following binary shaftencoder have when the detector is on thetransition 100 011?

    BinaryEncoderdisk

    000001010011

    100101110111

    ClockwiseSequence

    Detector3 Sensors

    S2 S1 S0

    S2S1S0

  • 7/27/2019 1.Number Systems

    45/48

    HET202 Digital Electronics Design 45

    Shaft Encoder Timing

    1002=4 0112=31102=6

    100 011

    1112=7

    Close-up of100->011 transition

    Skewed transitionsdue to tolerancesbetween sensors

    (position,threshold).

    S2

    S1

    S0

    Shaft appears to jump aroundin position although it is onlymoving a very small amount.

    4 6 7 3

  • 7/27/2019 1.Number Systems

    46/48

    HET202 Digital Electronics Design 46

    A Unit-distance Code

    Binary encoderdisk

    Unit distanceencoder disk

    Only 1-bit changesat each transition

    000

    001

    010

    011100

    101

    110

    111

    000

    001

    101

    100110

    111

    011

    010

  • 7/27/2019 1.Number Systems

    47/48

    HET202 Digital Electronics Design 47

    Character Codes -ASCII0 1 2 3 4 5 6 7 8 9 A B C D E F

    0 nul soh stx etx eot enq ack bel bs ht lf vt ff cr so si

    1 dle dc1 dc2 dc3 dc4 nak syn etb can em sub esc fs gs rs us

    2 sp ! " # $ % & ' ( ) * + , - . /

    3 0 1 2 3 4 5 6 7 8 9 : ; < = > ?

    4 @ A B C D E F G H I J K L M N O

    5 P Q R S T U V W X Y Z [ \ ] ^ _

    6 ` a b c d e f g h i j k l m n o7 p q r s t u v w x y z { | } ~ del

    Second Digit

    FirstDi

    git

    ASCII 7-bit code used to represent common English

    characters (subset of international set).

  • 7/27/2019 1.Number Systems

    48/48

    HET202 Digital Electronics Design 48

    Other Codes

    See text 8-4-2-1 (BCD)

    6-3-1-1

    Excess-3 2-out-of-5

    Gray code (similar to unit distance example)

    Unicode (character code able to represent thecharacters of many languages)


Recommended