Ary Numbers

download Ary Numbers

of 27

Transcript of Ary Numbers

  • 8/11/2019 Ary Numbers

    1/27

  • 8/11/2019 Ary Numbers

    2/27

  • 8/11/2019 Ary Numbers

    3/27

    Unsigned Integers

    Computers process binary patterns, i.e. of patterns of 0s and 1s. To represent data 1within acomputer we need to code it as a binary pattern.

    The representation of integers2and characters are the most important to consider because more

    complicated data representations can be built from them, e.g. comple numbers, dates, times,addresses, sound, !ideo, typefaces.

    Computer architects ha!e employed many different schemes for representing numerical !alues, andthere are ad!antages and disad!antages to each representation. "efore considering these, we need toremind oursel!es about binary numbers.

    Binary numbers

    #s you $now, unsigned integer numbers can be represented in bases %radices& other than base ten%decimal&, for eample the decimal number 1' can be represented as 1( in base ) %octal& as 2' in base*, as 112 in base + %ternary&, and as 1110 in base 2 %binary&. These follow from the standard

    techniue of coding each position of the number as a power of the base-nd n1d .. . 0d .

    or a decimal number we ha!e- kdk=0

    n

    / k10 , while for a binary number kdk=0

    n

    /k

    2

    The second sum %for a binary number& also gi!es us a simple method to con!ert integers from base 2to base 10.

    Example: for the decimal number 2*2 we ha!e-

    252 1111 11003

    Decimal (Base 10) Binary (Base 2)

    MS LS MS LS

    2 * 2 1 1 1 1 1 1 0 0

    100 10 1 12) (' +2 1( ) ' 2 1

    102

    101

    100

    2

    2(

    2*

    2'

    2+

    22

    21

    20

    ere MS stands for Most Significantand signifies the leftmost digit or bit. LSstands for LeastSignificantand signifies the rightmost digit or bit.

    e can ma$e the base of a number eplicit by suffiing it to the number as a subscript-

    1'10

    3 1()3 2'

    *3 112

    +3 1110

    2

    4n some computer languages we suffi the letter " %or b& to binary !alues e.g. 101"

    1 ell also loo$ at how computer programs are represented later in the course.2 ell also loo$ at the approimation of real numbers using floating5point numbers later in the course.+ 6paces or underscores in binary numbers are added for readability. 6paces7underscores between groups of ' bits

    %grouping right5to5left& is common.

  • 8/11/2019 Ary Numbers

    4/27

    Decimal to Binary Conversion (Division)

    There are se!eral ways of con!erting decimal numbers to binary. # simple techniue in!ol!es repeateddi!ision by 2.

    Example: What is 9810

    in binary?

    6teps-

    8 9i!ide the number by 2 gi!ing the uotient and the remainder.

    8 :epeat pre!ious step with the new uotient until a ;ero uotient is obtained.

    8 The answer is obtained by reading the remainder column from the bottom to the top.

    Quotient Remainder

    98 2 49 0

    49 2 24 1

    24 2 12 0

    12 2 6 0

    6 2 3 0

    3 2 1 1

    1 2 0 1

    #nswer- 110 00102 reading the remainder column from bottom to the top

  • 8/11/2019 Ary Numbers

    5/27

  • 8/11/2019 Ary Numbers

    6/27

    BinaryOctal (Base 8) Conversion

    4n the past'programmers sometimes used octal as a more con!enient base for representing long binary!alues. The octal representation is shorter and the con!ersion from binary to octal and !ice5!ersa is

    straightforward. The basic rule of thumb for an octal !alue is-

    6tarting from the rightmost (least significant) en, each group of + bits represents 1 octal digit%called an octet&.

    000 %0&, 001 %1&, 010 %2&, 011 %+&, 100 %'&, 101 %*&, 110 %(&, 111 %&

    Example- What is 101012

    in octal?

    10 101

    2 5

    #nswer- 2*)

    Example- What is 3578

    in binary?

    3 5 7

    011 101 111

    #nswer- 111011112

    ' #lthough octal is less used these days, you should be familiar with the term.

  • 8/11/2019 Ary Numbers

    7/27

    Hexadecimal (Base 16)

    eadecimal %he& has o!erta$en octal as the radi used by programmers to represent long binary!alues. "inary !alues can be integers, characters, real numbers, memory addresses, instructions, etc

    e will use headecimal etensi!ely, so it is important to master con!ersions. 4t is also important tounderstand that headecimal and decimal are con!eniences for humans, the computer representse!erything in binary only. e will not perform arithmetic in headecimal, only use it as a shorthand forwriting binary !laues.

    6tarting from the rightmost (least significant) en, each group of ' bits represents 1 he digit. euse the symbols 0, 1, 2, +, ', *, (, , ), B, #, ", C, 9, , for these. The letters # to can be inuppercase or lowercase.

    e can summarise the correspondence between headecimal, decimal and binary with the followingtable-

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

    Decimal 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

    Binary 0 1 10 11 100 101 110 111 1000 1001 1010 1011 1100 1101 1110 1111

    Example: What is 25210

    = 1111 11002

    in hexadecimal?

    1111 1100

    F C

    #nswer. C1(

    !ote- e will sometimes use the suffi the letter %or h& after a headecimal !alue instead of thesubscript 1(, e.g. 2#+. #nother alternati!e that is used in some programming languages is to

    prefi the headecimal !alue with 0, e.g. 02#+

  • 8/11/2019 Ary Numbers

    8/27

    Radix Arithmetic

    Aerforming addition, subtraction, multiplication and di!ision in bases other that 10 is identical todecimal arithmetic ecept that we use the particular base as the point of reference instead of 10.

    6ome eamples should ma$e this clear.

    "ition "#

    $ B#

    or$ing from :ight to =eft%hiledigits remain to be added

    #dd current digits of # and "&f6D< is less than :

    thenrecord 6D