Number Systems for Students

Embed Size (px)

Citation preview

  • 8/8/2019 Number Systems for Students

    1/38

    Number Systems

    Decimal

    Binary

    Octal

    Hexadecimal

  • 8/8/2019 Number Systems for Students

    2/38

    Decimal (base 10) Binary (Base 2) Octal (Base 8) Hexadecimal (Base 16)

    00 0000 00 0

    01 0001 01 1

    02 0010 02 2

    03 0011 03 3

    04 0100 04 4

    05 0101 05 5

    06 0110 06 6

    07 0111 07 7

    08 1000 10 8

    09 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

  • 8/8/2019 Number Systems for Students

    3/38

    Conversion from base r to decimal

  • 8/8/2019 Number Systems for Students

    4/38

    Decimal System

    Radix or base 10

    10 digits (0,1,2,9) Coefficients are multiplied by powers of 10

    Example:

  • 8/8/2019 Number Systems for Students

    5/38

    Octal (base-8) to Decimal

    System Radix or base 8

    8 digits (0,1,2,3,4,5,6,7) Coefficients are multiplied by powers of 8

    Example:

  • 8/8/2019 Number Systems for Students

    6/38

    Hexadecimal (base-16) to decimal

    system Radix or base 16

    16 digits (0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F) Coefficients are multiplied by powers of 16

    Example:

  • 8/8/2019 Number Systems for Students

    7/38

    Binary (base-2) to decimal

    System Radix or base 2

    2 digits (0,1) Coefficients are multiplied by powers of 2

    Example:

  • 8/8/2019 Number Systems for Students

    8/38

    Examples: convert to decimal

    equivalent(511.4)10

    (408.5)10

    (46687)10

    (4021.2)5 =

    (630.4)8 =

    (B65F)16 =

  • 8/8/2019 Number Systems for Students

    9/38

    Conversion from decimal to base r

  • 8/8/2019 Number Systems for Students

    10/38

    Convert Decimal to Binary (Integer

    Part)Example: 50 (divide by 2)

    (0110010)2

  • 8/8/2019 Number Systems for Students

    11/38

    Convert Decimal to binary

    (Fraction Part)Example: 0.625 (multiply by 2)

    (0.101)2

  • 8/8/2019 Number Systems for Students

    12/38

    Convert Decimal to Binary (Integer

    and fraction )Task:

    (41)10 to (bbbb)2(0.6875)10 to (bbbb)2

    (41.6875)10 to (bbbb)2

    (101001.1011) to (ddd)10

    (101001)2

    (0.1011)2

    (101001.1011)2

  • 8/8/2019 Number Systems for Students

    13/38

  • 8/8/2019 Number Systems for Students

    14/38

  • 8/8/2019 Number Systems for Students

    15/38

    Convert from Decimal to

    Hexadecimal and backExample:

    (450)10 to (hhh)16 divide by 16

    (1C2)16 to (ddd)10 multiply by powers of 16

    (0.521)10 to (hhh)16 mulitply by 16(0.8560)16 to (ddd)10 multiply by powers of 16

  • 8/8/2019 Number Systems for Students

    16/38

    Why octal and hexadecimal ??

    23 = 8 and 24=16

    3 digits required for octal

    4 digits required for hexadecimal

    (10 110 001 101 011.111 100 000 110)2=(26153.7406)

    8

    2 6 1 5 3 7 4 0 6

    (10 1100 0110 1011.1111 0000 0110)2=(2C6B.F06)162 C 6 B F 0 6

  • 8/8/2019 Number Systems for Students

    17/38

    Why octal and hexadecimal ??

    Each octal digit converted to its 3 bit

    binary equivalent Each hexadecimal digit converted to its 4

    bit binary equivalent(673.124)8=(110 111 011.001 010 100)26 7 3 1 2 4

    (306.D)16=(0011 0000 0110. 1101)

    2

    3 0 6 D

  • 8/8/2019 Number Systems for Students

    18/38

    Complements

  • 8/8/2019 Number Systems for Students

    19/38

    Binary Numbers

    An N-bit number a = aN-1 aN-2..a2a1 a0

    maybe treated as signed or unsignednumber.

    Unsigned Number: All the Nbits of anunsigned number are used to express themagnitude of the number.

  • 8/8/2019 Number Systems for Students

    20/38

    Numbers

  • 8/8/2019 Number Systems for Students

    21/38

    Signed-Magnitude

    Designate left-most bit as a signbit with no

    arithmetic weight 1-> negative, 0-> positive. Easy to determine sign

    Positive and negative zero (0000 vs. 1000)

    Difficult to add numbers of different sign orsubtract numbers of same sign (comparison)

    N-1 bits are available to represent magnitude Range of N-bit signed-magnitude number is:

    -(2N-11) to (2N-11)

  • 8/8/2019 Number Systems for Students

    22/38

    Signed-Magnitude

    Advantages

    intuitive appeal & conceptual simplicity symmetric range

    simple negation

    Disadvantages

    fewer numbers encoded (two encodings for 0)

    subtraction is more complicated than in 2s-comp

  • 8/8/2019 Number Systems for Students

    23/38

    2s ComplementExample: 2s complement ve number

  • 8/8/2019 Number Systems for Students

    24/38

    2s Complement

    A specific case of radix complement

    To negate or complementan Ndigitnumber, subtract it from 2N.

    If you then add the number and itscomplement, you get 2N.

    If you only keep N-digits (discard finalcarry), you have zero.

  • 8/8/2019 Number Systems for Students

    25/38

    2s Complement

    However, we need an extra bit to allow

    both positive and negative numbers. 7 is 0111

    -7 is computed as 16-7=9 10000 - 0111 = 1001 = -7

    Add 7 and 7, discard carry, we get 0 0111 + 1001 = 1_0000

  • 8/8/2019 Number Systems for Students

    26/38

    2s Complement

  • 8/8/2019 Number Systems for Students

    27/38

    2s Complement

    2 C l t

  • 8/8/2019 Number Systems for Students

    28/38

    2s ComplementExample: 2s complement ve number

    E l U i N

  • 8/8/2019 Number Systems for Students

    29/38

    Example: Unsigned Number

  • 8/8/2019 Number Systems for Students

    30/38

    2s ComplementExample of Equivalent Representation

    2s Complement

  • 8/8/2019 Number Systems for Students

    31/38

    2s Complement2s Representation of 4-bit Numbers & Their Unsigned Equivalent Numbers

    2s Complements

  • 8/8/2019 Number Systems for Students

    32/38

    2 s ComplementsRepresentation Characteristics

    The representation of ve No. facilitates theH/W implementation of many basic arithmetic

    operations This representation is widely used for

    executing arithmetic operation in specified

    algorithms and general purpose architecture In the example, the minimum +ve No. is 0 and

    maximum +ve No. is 7

    The min ve No. is -8 There is no equal opposite of -2N-1 in Nbits2s complement representation

  • 8/8/2019 Number Systems for Students

    33/38

    2s Complements

    Method1

    we move from LSB to MSB leaving thefirst Non-Zero bit as it is and flipping all therest of the bits.

    This is certainly not the best way of taking2c complement in H/W

    2s complement of 0010 is 1110

  • 8/8/2019 Number Systems for Students

    34/38

    2s Complements

  • 8/8/2019 Number Systems for Students

    35/38

    Overflow

    overflow occurs when:

    POS+POS=NEG or NEG+NEG=POS

    Addition/subtraction and

  • 8/8/2019 Number Systems for Students

    36/38

    Addition/subtraction and

    Overflow +3 0011 +5 0101 +5 0101

    +4 0100 +6 0110 -6 1010

    -------- -------- ---

    +7 0111 +11 1011 -1 1111

    -5 1011 -3 1101 -5 1011

    +6 0110 -4 1100 -6 1010

    -------- -------- -------

    +1 0001 -7 1001 -11 0101

  • 8/8/2019 Number Systems for Students

    37/38

    Multiplication (Unsigned)

    Example: 0101 * 0011 (5 * 3)

  • 8/8/2019 Number Systems for Students

    38/38

    2s Complement Sign Extension

    Store 1101 (-3) in an 8 bit register

    How to fix the problem??

    Example: 0101 * 0011 (5 * 3) Answer = 1111 (is it 15 or -1??)

    How to Fix the problem??