revision01 numbering systems

Upload: brett-wildermoth

Post on 04-Apr-2018

222 views

Category:

Documents


0 download

TRANSCRIPT

  • 7/29/2019 Revision01 Numbering Systems

    1/59

    Number Systems R1

    1

  • 7/29/2019 Revision01 Numbering Systems

    2/59

    Humans and the importance of small electricalpulses...

    2

  • 7/29/2019 Revision01 Numbering Systems

    3/59

    Input

    Hearing electrical pulses

    Smells electrical pulses

    Tastes electrical pulses

    Sight electrical pulses

    Touch

    electrical pulses

    Humans and the importance of small electricalpulses...

    3

  • 7/29/2019 Revision01 Numbering Systems

    4/59

    Humans and the importance of small electricalpulses...

    Output

    Electrical pulses

    movement

    Electrical pulses speech

    4

  • 7/29/2019 Revision01 Numbering Systems

    5/59

    The importance of numbers Gives meaning to our lives...

    Basis of our monetary system...

    HumansInput: Electrical Pulses

    Output: Electrical Pulses

    MicroprocessorsInput: Numbers

    Output: Numbers5

  • 7/29/2019 Revision01 Numbering Systems

    6/59

    Number SystemsThe most important number systems to

    programmers of

    Ps, are: The Binary Number System,

    The Octal Number System,

    The Hexadecimal Number System,

    And The Binary Coded Decimal (BCD)Number System

    6

  • 7/29/2019 Revision01 Numbering Systems

    7/59

    Rules of Counting

    There are 3 rules.......

    7

  • 7/29/2019 Revision01 Numbering Systems

    8/59

    Number SystemsRules for counting

    Rule 1:The number of fundamental digits or discrete levels in a number

    system equals the base or radix.

    Eg.

    16Hexadecimal

    8Octal2Binary

    10Decimal

    Radix / BaseNumber System

    8

  • 7/29/2019 Revision01 Numbering Systems

    9/59

    Number SystemsRules for counting

    Rule 2:

    Counting in discrete steps includes counting from the lowestfundamental digit to the highest. Once complete a column-placingtechnique is used, the digit is reset to the lowest fundamental digitand the digit to the left is incremented by a fundamental unit.

    9

  • 7/29/2019 Revision01 Numbering Systems

    10/59

    Number SystemsRules for counting

    Rule 3Each digits position in the column is of significant importance. The

    digit to the extreme right is the digit of least significant or leastvalue, and the digit to the extreme left has the greatest value.

    A digit always begins in the leftmost column.

    DigitDigitDigitDigit

    Base0Base1Base2Base3

    10

  • 7/29/2019 Revision01 Numbering Systems

    11/59

    The Decimal Number SystemRevision

    The decimal number system has a radix or baseof 10 and consists of the digits:

    0 1 2 3 4 5 6 7 8 9Decimal numbers are constructed using only these

    digits and each column in the number increases

    by a power of 10.e.g.

    5374 = 4 x 100 + 7 x 101 + 3 x 102 + 5 x 103

    11

  • 7/29/2019 Revision01 Numbering Systems

    12/59

    Many mathematical operations can be applied todecimal numbers. However only the basicoperators are implemented in a P, such as:

    Addition,

    Subtraction,

    Multiplication,

    and Division

    The Decimal Number SystemRevision

    12

  • 7/29/2019 Revision01 Numbering Systems

    13/59

    Starting at the least significant digits of both numbers the top digit isincremented by the lower digit, if this increment exceeds the limit of

    the digits then a carry condition occurs. The carry condition insertsan additional 1 to the column directly to the right that is introducedto the summation. This procedure is repeated until the two mostsignificant numbers are added.

    4

    3

    9

    3+

    The Decimal Number SystemRevision

    13

  • 7/29/2019 Revision01 Numbering Systems

    14/59

    Starting at the least significant digits of both numbers the top digit isincremented by the lower digit, if this increment exceeds the limit of

    the digits then a carry condition occurs. The carry condition insertsan additional 1 to the column directly to the right that is introducedto the summation. This procedure is repeated until the two mostsignificant numbers are added.

    4

    23

    9

    3+1

    The Decimal Number SystemRevision

    13

  • 7/29/2019 Revision01 Numbering Systems

    15/59

    Starting at the least significant digits of both numbers the top digit isincremented by the lower digit, if this increment exceeds the limit of

    the digits then a carry condition occurs. The carry condition insertsan additional 1 to the column directly to the right that is introducedto the summation. This procedure is repeated until the two mostsignificant numbers are added.

    4

    23

    9

    3

    1

    +

    The Decimal Number SystemRevision

    13

  • 7/29/2019 Revision01 Numbering Systems

    16/59

    Starting at the least significant digits of both numbers the top digit isincremented by the lower digit, if this increment exceeds the limit of

    the digits then a carry condition occurs. The carry condition insertsan additional 1 to the column directly to the right that is introducedto the summation. This procedure is repeated until the two mostsignificant numbers are added.

    4

    23

    9

    38

    1

    +

    The Decimal Number SystemRevision

    13

  • 7/29/2019 Revision01 Numbering Systems

    17/59

    Starting at the least significant digits of both numbers the top digit isdecremented by the lower digit, if this decrement is lower than zerothen a borrow condition occurs. The borrow condition incrementsthe number by the base (10) and reduces the number to the right byone fundamental digit. The lower number is then subtracted from theupper number. This procedure is repeated until the two mostsignificant numbers are added.

    2

    33

    8

    -

    The Decimal Number SystemRevision

    14

  • 7/29/2019 Revision01 Numbering Systems

    18/59

    Starting at the least significant digits of both numbers the top digit isdecremented by the lower digit, if this decrement is lower than zerothen a borrow condition occurs. The borrow condition incrementsthe number by the base (10) and reduces the number to the right byone fundamental digit. The lower number is then subtracted from theupper number. This procedure is repeated until the two mostsignificant numbers are added.

    2

    33

    8-1

    -

    1

    The Decimal Number SystemRevision

    14

  • 7/29/2019 Revision01 Numbering Systems

    19/59

    Starting at the least significant digits of both numbers the top digit isdecremented by the lower digit, if this decrement is lower than zerothen a borrow condition occurs. The borrow condition incrementsthe number by the base (10) and reduces the number to the right byone fundamental digit. The lower number is then subtracted from theupper number. This procedure is repeated until the two mostsignificant numbers are added.

    2

    39

    3

    8-1

    -

    1

    The Decimal Number SystemRevision

    14

  • 7/29/2019 Revision01 Numbering Systems

    20/59

    Starting at the least significant digits of both numbers the top digit isdecremented by the lower digit, if this decrement is lower than zerothen a borrow condition occurs. The borrow condition incrementsthe number by the base (10) and reduces the number to the right byone fundamental digit. The lower number is then subtracted from theupper number. This procedure is repeated until the two mostsignificant numbers are added.

    4

    2

    39

    3

    8-1

    -

    1

    The Decimal Number SystemRevision

    14

  • 7/29/2019 Revision01 Numbering Systems

    21/59

    Binary Number System

    The binary number system has a radix or base of 2 andconsists of the digits

    0 1 The beauty of the binary system is that it directly relates

    to logical states of circuits, they are either ON or OFF.

    Binary numbers are constructed using only thefundamental digits 0 and 1.

    It is obvious that more binary digits must be used thanwould necessarily be needed to represent decimalnumbers.

    15

  • 7/29/2019 Revision01 Numbering Systems

    22/59

    Binary Number SystemConversion to Decimal

    Each column in a binary number increases by apower of 2, the least significant column is 20 the

    next 2

    1

    and so forth. The process of converting a number from binary

    to decimal is as simple as multiplying the binarynumber by the associated column weights andadding the results.

    For example:1011001b = 1 x 20 + 0 x 21 + 0 x 22 + 1 x 23 + 1 x 24 + 0 x 25 + 1 x 26

    = 89d

    16

  • 7/29/2019 Revision01 Numbering Systems

    23/59

    Binary Number SystemConversion from Decimal

    The conversion from Decimal to binary is achieved by dividing thedecimal number by 2 and noting the remainder, the process isrepeated until zero remains.

    For example

    145/2 = 72 remainder =172/2 = 36 remainder =0

    36/2 = 18 remainder =0

    18/2 = 9 remainder =0

    9/2 =4 remainder =1

    4/2 = 2 remainder =02/2 = 1 remainder =0

    = 0 remainder = 1

    Therefore 145 is 10010001 in binary.

    Check:

    1 x 20 + 0 x 21 + 0 x 22 + 0 x 23 + 1 x 24 +

    0 x 25 + 0 x 26 + 1 x 27 = 145

    17

  • 7/29/2019 Revision01 Numbering Systems

    24/59

    Binary Number SystemBinary Addition

    Adding binary numbers is similar to adding decimal

    numbers, you start by adding the least significantdigits, making your way to the most significant,carrying were necessary.

    Example:

    1110

    + 0110

    18

  • 7/29/2019 Revision01 Numbering Systems

    25/59

    Binary Number SystemBinary Addition

    Adding binary numbers is similar to adding decimal

    numbers, you start by adding the least significantdigits, making your way to the most significant,carrying were necessary.

    Example:

    1110

    + 0110

    0

    18

  • 7/29/2019 Revision01 Numbering Systems

    26/59

    Binary Number SystemBinary Addition

    Adding binary numbers is similar to adding decimal

    numbers, you start by adding the least significantdigits, making your way to the most significant,carrying were necessary.

    Example:

    1110

    + 0110

    001

    18

  • 7/29/2019 Revision01 Numbering Systems

    27/59

    Binary Number SystemBinary Addition

    Adding binary numbers is similar to adding decimal

    numbers, you start by adding the least significantdigits, making your way to the most significant,carrying were necessary.

    Example:

    1110

    + 0110

    00

    1

    18

  • 7/29/2019 Revision01 Numbering Systems

    28/59

    Binary Number SystemBinary Addition

    Adding binary numbers is similar to adding decimal

    numbers, you start by adding the least significantdigits, making your way to the most significant,carrying were necessary.

    Example:

    1110

    + 0110

    00

    1

    11

    18

  • 7/29/2019 Revision01 Numbering Systems

    29/59

    Binary Number SystemBinary Addition

    Adding binary numbers is similar to adding decimal

    numbers, you start by adding the least significantdigits, making your way to the most significant,carrying were necessary.

    Example:

    1110

    + 0110

    00

    1

    1

    1

    18

  • 7/29/2019 Revision01 Numbering Systems

    30/59

    Binary Number SystemBinary Addition

    Adding binary numbers is similar to adding decimal

    numbers, you start by adding the least significantdigits, making your way to the most significant,carrying were necessary.

    Example:

    1110

    + 0110

    00

    1

    1

    1

    10

    18

  • 7/29/2019 Revision01 Numbering Systems

    31/59

    Binary Number SystemBinary Subtraction

    The procedure for subtracting binary numbers issimilar to that for decimal numbers. If a digit is

    smaller than the digit being subtracted, then aborrow occurs from the column to the right.

    Example:

    1110

    - 0110

    19

  • 7/29/2019 Revision01 Numbering Systems

    32/59

    Binary Number SystemBinary Subtraction

    The procedure for subtracting binary numbers issimilar to that for decimal numbers. If a digit is

    smaller than the digit being subtracted, then aborrow occurs from the column to the right.

    Example:

    1110

    - 0110

    0

    19

  • 7/29/2019 Revision01 Numbering Systems

    33/59

    Binary Number SystemBinary Subtraction

    The procedure for subtracting binary numbers issimilar to that for decimal numbers. If a digit is

    smaller than the digit being subtracted, then aborrow occurs from the column to the right.

    Example:

    1110

    - 0110

    00

    19

  • 7/29/2019 Revision01 Numbering Systems

    34/59

    Binary Number SystemBinary Subtraction

    The procedure for subtracting binary numbers issimilar to that for decimal numbers. If a digit is

    smaller than the digit being subtracted, then aborrow occurs from the column to the right.

    Example:

    1110

    - 0110

    000

    19

  • 7/29/2019 Revision01 Numbering Systems

    35/59

    Binary Number SystemBinary Subtraction

    The procedure for subtracting binary numbers issimilar to that for decimal numbers. If a digit is

    smaller than the digit being subtracted, then aborrow occurs from the column to the right.

    Example:

    1110

    - 0110

    0001

    19

  • 7/29/2019 Revision01 Numbering Systems

    36/59

    Octal Number System

    The octal number system has a radix or base ofeight and consists of the fundamental digits,

    0 1 2 3 4 5 6 7

    Octal numbers are created using only thesedigits.

    Counting with octal numbers commences at 0

    and continues to 7, the least significant numberis reset to 0 and the digit 1 is inserted to theleft forming 10.

    20

  • 7/29/2019 Revision01 Numbering Systems

    37/59

    Octal Number SystemConversion to Decimal

    The conversion from octal to decimal dependshighly on the column placing model discussedearlier. Each column in the number is increased bya power of eight.

    For example

    1534o = 4 x 80 + 3 x 81 + 5 x 82 + 1 x 83

    = 860d

    21

  • 7/29/2019 Revision01 Numbering Systems

    38/59

    Octal Number SystemConversion from Decimal

    The conversion of a decimal number to an octal numberis performed in the same way as converting a decimalnumber to binary. However, since the base is 8 instead of

    2 the divisor is in fact 8 in this instance.For example:

    145 / 8 = 18 remainder = 1

    18 / 8 = 2 remainder = 2

    2 / 8 = 0 remainder = 2

    Therefore 145d is in fact 221 in octal.

    Check:

    221o = 1 x 80 + 2 x 81 + 2 x 82

    =145d

    22

  • 7/29/2019 Revision01 Numbering Systems

    39/59

    Octal Number SystemConversion to and from Binary

    Since the radix of of the octal number system is a powerof 2, conversion two and from binary is made simple.

    Since 8 is 23, segments of three bits are used in the

    conversion to and from binary. To Binary:

    For each octal digit the corresponding 3 bit binary number can befound and the resulting bit segments concatenated together.

    For example:

    516o = 5 1 6 = 101 001 110

    = 101001110b

    23

  • 7/29/2019 Revision01 Numbering Systems

    40/59

    Octal Number SystemConversion to and from Binary

    From Binary

    For each three bit segment thecorresponding octal digit can be found and

    concatenated.

    For example:

    101001110b = 101 001 110 5 1 6

    = 516o

    24

  • 7/29/2019 Revision01 Numbering Systems

    41/59

    Hexadecimal Number

    The hexadecimal number system has a radix orbase of 16 and consists of the followingfundamental digits,

    0 1 2 3 4 5 6 7 8 9 A B C D E F

    Hexadecimal number are created using thesefundamental digits.

    25

  • 7/29/2019 Revision01 Numbering Systems

    42/59

    Hexadecimal Number SystemConversion to Decimal

    The conversion from hexadecimal to decimal is simple ifyou keep in mind each column in the number increases bya factor of 16.

    For example:

    FC81h = 1 x 160 + 8 x 161 + 12(C) x 162 + 15(F) x 163

    = 64641d

    It is obvious from this example that less digits are need torepresent decimal numbers in hexadecimal.

    26

  • 7/29/2019 Revision01 Numbering Systems

    43/59

    From decimal to hexadecimal.

    64641 / 16 = 4040 remainder = 1

    4040 / 16 = 252 remainder = 8

    252 / 16 = 15 remainder = 12 (C)

    15 /16 = 0 remainder = 15 (F)

    Therefore 64641d is in fact FC81h

    Hexadecimal Number SystemConversion to Hexadecimal

    27

  • 7/29/2019 Revision01 Numbering Systems

    44/59

    Hexadecimal Number SystemConversion to and from Binary

    To Binary:For each hexadecimal digit the corresponding four bit number can be

    calculated and the resulting bit segments joined together.

    For example:

    FC81h = F C 8 1

    = 1111 1100 1000 0001

    = 1111110010000001b

    28

  • 7/29/2019 Revision01 Numbering Systems

    45/59

    Hexadecimal Number SystemConversion to and from Binary

    From Binary:

    Segments of four bits are selected and a

    hexadecimal digit found for each segment.For Example:

    1011001011000101b = 1011 0010 11000101

    = B 2 C 5 = B2C5h

    29

    B C d d D l

  • 7/29/2019 Revision01 Numbering Systems

    46/59

    Binary Coded Decimal

    Only the binary numbers that represent the decimalnumbers from 0 to 9 are valid in each 4 bit set.

    101 100

    XXXX XXXX

    Using 8 bits a decimal number

    between 0 and 99 can be

    represented

    30

    R i N i

  • 7/29/2019 Revision01 Numbering Systems

    47/59

    Representing Negative

    Integers

    The signed modulus / sign bit extensionThe ones complement method

    The twos complement method

    31

    Si d M d l

  • 7/29/2019 Revision01 Numbering Systems

    48/59

    Signed Modulus

    Most Significant Bit represents the sign:

    0 means positive,

    1 means negative.

    32

    Si d M d l

  • 7/29/2019 Revision01 Numbering Systems

    49/59

    Signed ModulusProblems

    The signed modulus method contains two problems.

    Problem # 1:

    10000010-2

    10000001-1

    000000000

    000000011

    000000102

    000000113

    000001004

    000001015

    If 00000000 is the binary equivalent of zero

    then what is 10000000, -0 perhaps.

    The signed modulus method is inefficient,

    it contains two different methods ofrepresenting zero.

    33

    Si d M d l

  • 7/29/2019 Revision01 Numbering Systems

    50/59

    Signed ModulusProblems

    Problem #2:

    No additive Inverse

    Example:

    Does 34 + -34 = 0

    00100010 + 10100010 = 1100010034 + -34 = - 68

    34

    O C l

  • 7/29/2019 Revision01 Numbering Systems

    51/59

    Ones Complement

    The ones complement of 37 would becalculated as follows:

    Firstly find the 8 bit binary equivalent of 37. 37d = 00100101b Then invert each digit, resulting in -37d = 11011010b

    35

    T C l t

  • 7/29/2019 Revision01 Numbering Systems

    52/59

    Twos Complement

    A method of representing negative numbers commonly usedin binary arithmetic is the twos complement.

    The procedure for finding the twos complement is: Firstly, convert the number into its binary representation. 37d = 00100101b

    Secondly, invert all the bits of the number.

    = 11011010b

    Finally, add 1 to this number.

    11011010 + 1

    -37d = 11011011b

    36

    T C l t

  • 7/29/2019 Revision01 Numbering Systems

    53/59

    Twos Complement

    The two complement is a successful method for finding an additivenegative binary number. This can be proven using a 3 bit example.

    Check:

    011

    + 101

    (1)000

    Check:

    010+ 110

    (1)000

    100

    011 3

    010 2

    001 1

    000 0

    111 -1

    110 -2101 -3

    100

    37

    M lti d N b

  • 7/29/2019 Revision01 Numbering Systems

    54/59

    Multi-word Numbers

    Microprocessors have a fixed word size. Limited range of numbers.

    How do we represent bigger numbers?

    38

    M lti ord N mbers

  • 7/29/2019 Revision01 Numbering Systems

    55/59

    Multi-word Numbers

    An 8 bit microprocessor

    8 bit word length

    numbers ranging value from 0 to 255

    How could it represent a larger decimal number

    such as 3867?3867d = 0000111100011011b

    39

    Multi word Numbers

  • 7/29/2019 Revision01 Numbering Systems

    56/59

    Multi-word Numbers

    By splitting the 16 bit number into two 8 bit

    components.3867d = 0000111100011011b

    location number 1 = 00001111 (15) MSB

    location number 2 = 00011011 (27) LSB

    40

    Multi word Numbers

  • 7/29/2019 Revision01 Numbering Systems

    57/59

    Multi-word Numbers

    As mentioned earlier care must be made when dealing withmulti-word numbers. The significance of the numbersmust be taken into account.

    Example: 4326 + 1276

    16 bit Version:

    0001000011100110

    + 00000100111111000001010111100010

    8 bit Multi-word Version:

    LSB first: MSB second:

    11100110 00010000

    + 11111100

    00000100(1)11100010 + 1

    00010101

    = 0001010111100010

    41

    Multi-word Numbers

  • 7/29/2019 Revision01 Numbering Systems

    58/59

    Multi word NumbersBig Endian / Little Endian

    When representing 16 bit numbers by two 8 bit ones theycan be stored in memory either MSB first or LSB first.

    When the MSB is stored in a the memory locationpreceding the LSB, it is referred to asBig Endianrepresentation.

    When the MSB is stored after the LSB in memory it isknown as Little Endian.

    The S12X micro-controllers useBig Endian representationfor all 16 bit numbers used.

    Big Endian Little Endian

    0800:MSB

    0801:LSB

    0800:LSB

    0801:MSB

    42

    Need Further

  • 7/29/2019 Revision01 Numbering Systems

    59/59

    Assistance?

    Ask your Demonstrator,

    Post a question on the Forum, Email the Convener, or

    Make an appointment.

    43