csc159-chapter 2 part1

Upload: zainulsyafiq-ank-en-din

Post on 03-Apr-2018

225 views

Category:

Documents


0 download

TRANSCRIPT

  • 7/28/2019 Csc159-Chapter 2 Part1

    1/35

    MACHINE LEVEL REPRESENTATION OF DATA

    (Part 1)

    Prepared by: Nor Fauziah Binti Abu Bakar, FSKM

  • 7/28/2019 Csc159-Chapter 2 Part1

    2/35

    Contents1. Bits, bytes, and words

    2. Numeric data representation and number bases

    Binary, Octal, Hexadecimal3. Conversion between bases

  • 7/28/2019 Csc159-Chapter 2 Part1

    3/35

    Bits, Bytes, and Words

    Bits The basic unit of information in computing and

    telecommunication

    In computing, a bit is defined as a variable or computed

    quantity that can have only two possible These two values are often interpreted as binary digits and

    are usually denoted by 0 and 1

    In several popular programming languages, numeric 0 isequivalent (or convertible) to logicalfalse, and 1 to true.

    The correspondence between these values and the physicalstates of the underlying storage or device is a matter ofconvention, and different assignments may be used even

    within the same device or program

  • 7/28/2019 Csc159-Chapter 2 Part1

    4/35

    Bytes a unit of digital information in computing and

    telecommunications, that most commonly consists ofeight bits

    a byte was the number of bits used to encode a singlecharacter of text in a computer and it is for this reasonthe basic addressable element in many computerarchitectures.

    The byte size and byte addressing are often used inplace of longer integers for size or speed optimizationsin microcontrollers and CPUs

    Bits, Bytes, and Words - cont

  • 7/28/2019 Csc159-Chapter 2 Part1

    5/35

    Words In computing,word is a term for the natural unit of data

    used by a particular computer design A word is simply a fixed sized group of bits that are

    handled together by the system The number of bits in a word (theword size orwordlength) is an important characteristic of computerarchitecture.

    The size of a word is reflected in many aspects of a

    computer's structure and operation; the majority of theregisters in the computer are usually word sized and theamount of data transferred between the processing partcomputer and the memory system, in a single operation, ismost often a word

    Bits, Bytes, and Words - cont

  • 7/28/2019 Csc159-Chapter 2 Part1

    6/35

    NUMBERING SYSTEM :BASE

    PLACE

    5TH

    PLACE

    4TH

    PLACE

    3RD

    PLACE

    2ND

    PLACE

    1ST

    PLACE

    SINGLE

    UNIT

    1ST

    PLACE

    2ND

    PLACE

    3RD

    PLACE

    DECIMAL

    105 104 103 102 101 100 10-1 10-2 10-3

    100,000 10,000 1,000 100 10 1 0.1 0.01 0.001

    1/10 1/100 1/1000

    BINARY

    25 24 23 22 21 20 2-1 2-2 2-3

    32 16 8 4 2 1 0.5 0.25 0.125

    1/2 1/4 1/8

    OCTAL

    85 84 83 82 81 80 8-1 8-2 8-3

    32,768 4,096 512 64 8 1 0.125 0.0156251.953125

    X 103

    1/8 1/64 1/512

    HEXA-

    DECIMAL

    165 164 163 162 161 160 16-1 16-2 16-3

    1,048,576

    65,536 4,096 256 16 1 0.06253.906 X

    1032.4414062 X 104

    1/16 1/256 1/4096

  • 7/28/2019 Csc159-Chapter 2 Part1

    7/35

    Radix :

    when referring to binary, octal, decimal,

    hexadecimal, a single lowercase letter appended tothe end of each number to identify its type.

    E.g.

    hexadecimal 45will be written as 45h

    octal 76will be written as 76o or 76q binary 11010011will be written as 11010011b

    Number Bases

  • 7/28/2019 Csc159-Chapter 2 Part1

    8/35

    Number System

    The following table shows the equivalent values for decimal numbers in binary,octal and hexadecimal:

  • 7/28/2019 Csc159-Chapter 2 Part1

    9/35

    Number System

    Decimal system: system ofpositional notation basedon powers of 10.

    Binary system: system ofpositional notation basedpowers of 2

    Octal system: system ofpositional notation based on

    powers of 8

    Hexadecimal system: system ofpositional notationbased powers of 16

  • 7/28/2019 Csc159-Chapter 2 Part1

    10/35

    Base: The number of different symbols required to represent any

    given number

    The larger the base, the more numerals are required

    Base 10: 0,1, 2,3,4,5,6,7,8,9

    Base 2: 0,1

    Base 8: 0,1,2, 3,4,5,6,7

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

    For a given number, the larger the base

    the more symbols required

    but the fewer digits needed

    Number System

  • 7/28/2019 Csc159-Chapter 2 Part1

    11/35

    EXAMPLE:

    Example #1:

    6516 10110 1458 110 01012

    Example #2:

    11C16 28410 4348 1 0001 11002

    Number System

  • 7/28/2019 Csc159-Chapter 2 Part1

    12/35

    Binary SystemWHY??

    Early computer design was decimal

    Mark I and ENIAC

    John von Neumann proposed binary data processing (1945)

    Simplified computer design

    Used for both instructions and data

    Natural relationship betweenon/off switches andcalculation using Boolean logic

    On Off

    True False

    Yes No

    1 0

  • 7/28/2019 Csc159-Chapter 2 Part1

    13/35

    A computer stores both instructions and data asindividual electronic charges.

    represent these entities with numbers requires a systemgeared to the concept ofon and offor true and false

    Binary is a base 2 numbering system

    each digit is either a 0 (off) or a 1 (on)

    Computers store all instructions and data as

    sequences of binary digit e.g. 010000010100001001001000011 = ABC

    Binary System

  • 7/28/2019 Csc159-Chapter 2 Part1

    14/35

    Binary System

    Each digit in binary number has a value depending on itsposition

    Example:

    The number 1002 means

    (1 X 2) + ( 0 X 2) + (0 X 2)

    4 + 0 + 0

    4

  • 7/28/2019 Csc159-Chapter 2 Part1

    15/35

    Base 2

    7/21/2013 15

  • 7/28/2019 Csc159-Chapter 2 Part1

    16/35

    Decimal System

    Decimal is a base 10 numbering system

    We use a system based on decimal digits to representnumbers

    Each digit in the number is multiplied by 10 raised to apower corresponding to that digit position.

    Example :

    The number 472810 means :

    (4 X 1000) + (7 X 100) + (2 X 10) + 84000 + 700 + 20 +8

    4728

  • 7/28/2019 Csc159-Chapter 2 Part1

    17/35

    Base 10

    7/21/2013 17

  • 7/28/2019 Csc159-Chapter 2 Part1

    18/35

    Octal System

    As known as base 8 numbering system

    There are only eight different digits available (0, 1, 2, 3,

    4, 5, 6, 7) Example :

    The number 7238 means

    (7 X 8) + (2 X 8) + (3 X 8)

    448 + 16 + 3467

  • 7/28/2019 Csc159-Chapter 2 Part1

    19/35

    Base 8

    7/21/2013 19

  • 7/28/2019 Csc159-Chapter 2 Part1

    20/35

    Hexadecimal System

    Hexadecimal is a base 10 numbering system

    Used not only to represent integers

    Also used to represent sequence of binary digits Example :

    The number 2C16 means:

    (2 X 16) + (C X 16)

    32+ 12

    44

  • 7/28/2019 Csc159-Chapter 2 Part1

    21/35

    Base 16

    7/21/2013 21

  • 7/28/2019 Csc159-Chapter 2 Part1

    22/35

    Conversion Between Bases

    1. Conversion of decimal to binary

    2. Conversion of decimal to octal

    3. Conversion of decimal to hexadecimal

    4. Conversion of binary to decimal5. Conversion of binary to octal

    6.Conversion of binary to hexadecimal

    7. Conversion of octal to decimal

    8.Conversion of octal to binary9.Conversion of hexadecimal to binary

    10.Conversion of hexadecimal to decimal

  • 7/28/2019 Csc159-Chapter 2 Part1

    23/35

    CONVERSION :

    DECIMAL OTHER BASES

  • 7/28/2019 Csc159-Chapter 2 Part1

    24/35

    Base 10 42

    2 ) 42 ( 0 Least significant bit2 ) 21 ( 1

    2 ) 10 ( 0

    2 ) 5 ( 1

    2 ) 2 ( 0

    2 ) 1 ( 1 Most significant bit

    0

    Base 2 101010

    Remainder

    Quotient

    From Base 10 to Base 2

  • 7/28/2019 Csc159-Chapter 2 Part1

    25/35

    Convert 3710 to binary.

    * MSB (most-significant-bit) : left most bit

    LSB (least-significant-bit) : right most bit

    37 2 = 18 balance 1 (LSB)18 2 = 9 balance 09 2 = 4 balance 14 2 = 2 balance 02 2 = 1 balance 01 2 = 0 balance 1 (MSB)

    Therefore , 3710 = 1001012

    From Base 10 to Base 2

  • 7/28/2019 Csc159-Chapter 2 Part1

    26/35

    What is the value of 37.687510 in binary?Steps :

    1. Convert the integer to binary by using method shown in previous

    slide.2. Convert the decimal point to binary by using the followingmethod.

    So, (0.6875)10 = (0.1011)2 ; Therefore, 37.687510 = 100101.10112

    0.6875X 2

    (MSB) 1 1.3750X 2

    0 0.7500

    X 21 1.5000X 2

    (LSB) 1 1.0000

    The 1 is saved asresult, then droppedand the processrepeated

    From Base 10 (decimal point) to Base 2

  • 7/28/2019 Csc159-Chapter 2 Part1

    27/35

    Base 10 135

    8) 135 ( 7 Least significant bit

    8) 16 ( 0

    8) 2 ( 2 Most significant bit

    0

    Base 8 207

    Quotient

    Remainder

    From Base 10 to Base 8

  • 7/28/2019 Csc159-Chapter 2 Part1

    28/35

    8 21 58 2 2

    0

    0.25x 8

    2 2.00

    From Base 10 (decimal point) to Base 8Convert 21.2510 to octal.

    Therefore,

    21.2510 = 25.28

  • 7/28/2019 Csc159-Chapter 2 Part1

    29/35

    Convert 21.2510 to octal. (OTHER METHOD)

    21

    2 = 10 balance 1 (LSB)10 2 = 5 balance 0

    5 2 = 2 balance 1

    2 2 = 1 balance 0

    1 2 = 0 balance 1 (MSB)

    So, 2110 = 101012

    Now, 0.25X 2

    (MSB) 0 0.50

    X 2

    (LSB) 1 1.00

    So, 0.2510 = 0.012

    From Base 10 (decimal point) to Base 8

    Therefore,

    Refer to conversion of binary to hexadecimal

    21.2510 = 010 101 . 0102

    = 25.28

  • 7/28/2019 Csc159-Chapter 2 Part1

    30/35

    Base 10 5,735

    16 ) 5,735 ( 7 Least significant bit

    16 ) 358 ( 6

    16 ) 22 ( 6

    16 ) 1 ( 1 Most significant bit

    0

    Base 16 1667

    Quotient

    Remainder

    From Base 10 to Base 16

  • 7/28/2019 Csc159-Chapter 2 Part1

    31/35

    Base 10 8,039

    16 ) 8,039 ( 7 Least significant bit

    16 ) 502 ( 6

    16 ) 31 ( 15

    16 ) 1 ( 1 Most significant bit

    0

    Base 16 1F67

    Quotient

    Remainder

    From Base 10 to Base 16

  • 7/28/2019 Csc159-Chapter 2 Part1

    32/35

    Convert 2110 to hexadecimal.

    21 16 = 1 balance 5 (LSB)

    1 16 = 0 balance 1 (MSB)

    Therefore , 2110 = 1516

    From Base 10 to Base 16

  • 7/28/2019 Csc159-Chapter 2 Part1

    33/35

    16 21 516 1 1

    0

    0.25x 16

    4 4.00

    From Base 10 (decimal point) to Base 16Convert 21.2510 to hexadecimal.

    Therefore,

    21.2510 = 15.416

  • 7/28/2019 Csc159-Chapter 2 Part1

    34/35

    Convert 21.2510 to hexadecimal. (OTHER METHOD)

    21

    2 = 10 balance 1 (LSB)10 2 = 5 balance 0

    5 2 = 2 balance 1

    2 2 = 1 balance 0

    1 2 = 0 balance 1 (MSB)

    So, 2110 = 101012

    Now, 0.25X 2

    (MSB) 0 0.50

    X 2

    (LSB) 1 1.00

    So, 0.2510 = 0.012

    From Base 10 (decimal point) to Base 16

    Therefore,

    Refer to conversion of binary to hexadecimal

    21.2510 = 10101 . 01002

    = 15.416

  • 7/28/2019 Csc159-Chapter 2 Part1

    35/35

    EXERCISES1. Find the binary representation for 31.62510.Show

    your work.

    1. Convert the following numbers to the respectivenumbering system.

    5610

    base 8 (until 5 binary point)

    2. Convert 95.2510 to hexadecimal.