Comic Integer and Float

  • Upload
    markthb

  • View
    222

  • Download
    0

Embed Size (px)

Citation preview

  • 8/10/2019 Comic Integer and Float

    1/7

    In the early days of computing, designers made computers express numbers using unsigned binar

    To include negative numbers, designers came up with sign magnitude.

    Then designers created ones complement.

    Finally, designers developed twos complement.

    But the computer had to count backwardsfor the negative numbers.

    Plus, this introduced positive and negative zero.

    Hey guys!do you ne

    number

  • 8/10/2019 Comic Integer and Float

    2/7

    Comparing Integer RepresentationsNegation and Zeroes

    Hi! And welcome to the Best IntegerRepresentation competition!

    Here, well choose who gets to be theworlds standard for computer integers!But first, lets introduce our contestants:

    Round 1 - Negation

    Round 2 - Zeroes

    In this competition, well use 8-bit numbers. Now lets get started!

    Unsigned SignMagnitude

    OnesComplement

    TwosComplement

    Bias

    Flip sign bit Flip all bitsFlipallbi

    ts

    andadd1

    Subtractfrom12710

    Oh, dear! It looks like Unsigned cant negate. But this competition has onlystarted, so Unsigned still has a chance of catching up to the others.

    0000 00001000 0000

    000000001111 1111

    0111111100000000

    Now things are getting interesting! Unsigned and Twos Complement get two points eachfor having one zero and being able to represent zero with all zero bits. Biass zero isnt allzero bits, but it gets a point for having only one zero. And though they have two zeroes,

    Sign Magnitude and Ones Complement get a point for having a zero of all zero bits.

    Round 1 is easy. Just tell mehow you negate a number!

    Now for Round 2! Show meall the ways you representzero!

    Um...

    00000000

    -1271

    -1271

    -127

    1

    0 1 1 1 1

    2 2 2 3 2

  • 8/10/2019 Comic Integer and Float

    3/7

    255

    0

    -255

    128

    -128

    00000000 01111111 11111111

    1

    -1

    127

    -127

    10000000

    255

    0

    -255

    128

    -128

    00000000 01111111 11111111

    1

    -1

    127

    -127

    10000000

    255

    0

    -255

    128

    -128

    00000000 01111111 11111111

    1

    -1

    127

    -127

    10000000

    255

    0

    -255

    128

    -128

    00000000 01111111 11111111

    1

    -1

    127

    -127

    10000000

    255

    0

    -255

    128

    -128

    00000000 01111111 11111111

    1

    -1

    127

    -127

    10000000

    Comparing Integer RepresentationsIncrements and Monotonicity

    Round 3 - Incrementing

    255

    0

    -255

    128

    -128

    00000000 01111111 11111111

    1

    -1

    127

    -127

    10000000

    Very nice! Unsigned has a graph that is continuousand has a unit slope. This means we can use an

    unsigned comparator to compare integers!Well give Unsigned two points for that.

    Whats this? Sign Magnitude has a very unusualincrement indeed. It has a unit slope for positiveintegers, but the slope becomes -1 for negatives.

    Sorry, but no points for Sign Magnitude this round.

    Another monotonically increasing graph with unitslope! You can use an unsigned comparator to

    compare integers here, too. Bias gets two points!

    Just like Ones Complement, Twos Complementhas a discontinuous graph and unit slope. So

    well give Twos Complement a point.

    Theres a discontinuity in the graph forOnes Complement, but we do like how

    it has a consistent unit slope.Thats one point for Ones Complement.

    4

    2 3

    4 4

    -12

    On to Round 3! Using this board, graph how your value changes when you

    increment your bit pattern from 00000000 to 11111111! Well give each playera point for having a continuous graph and a point for a consistent unit slope.

  • 8/10/2019 Comic Integer and Float

    4/7

    Unsigned

    Sign Magnitude

    Ones Complement

    Twos Complement

    Bias

    Comparing Integer RepresentationsThe Thrilling Conclusion!

    One Zero?Negation? Zero =0000 0000

    MonotonicaIncreasing

    Continuous?Weve finally arrived at theend of our competition. Letssee that scoreboard!

    Well, well! It appears we have a three-way tie among Unsigned, Twos Complement,and Bias! We can certainly give each of our winners a prize, though!

    Unsigned, youll be the representationfor data whenever users call upon theunsignedmodifier in C! Ive heard thatother languages use it, too, so youllwork for them as well.

    Bias, youll represent the exponent inIEEE-754 floating-point numbers! Thefact that we can compare exponentswith an unsigned comparator will come inhandy!

    And you, Twos Complement, becauseyou can negate and have one zero thatis expressed as all zero bits, you will bethe representation of integers forbinary computers all around the world!

    -12710

    unsignedchar foo = 24;

    000110002

    signedchar bar = -24;

    111010002

  • 8/10/2019 Comic Integer and Float

    5/7

    3.141592

    Floating-Point Numbers!

    An IEEE754 floating point number consists of three parts:

    (Also known as the Significand)

    the Exponent,the Sign, and the Mantissa.

    The Sign, as its name suggests,determines the sign of the number.

    The Exponent plays a vital role in determininghow big (or small) the number is. However, itsencoded so that unsigned comparison can be

    used to check floating-point numbers.

    To see the true magnitude of theExponent, youd need to subtract theBias, a special number determined bythe length of the Exponent.

    And last but not least, the Mantissaholds the significant digits of thefloating point number.

    +

    100000002

    0100000000000

    00000000002

    -12710

  • 8/10/2019 Comic Integer and Float

    6/7

    Floating-Point Numbers:All Together Now!

    0100000000000

    00000000002

    +

    Once all the parts of the floating-point number are obtained, convertingit to decimal is just a matter of applying the following formula:

    Notice that the Mantissa actually represents a fraction, instead of an integer!In addition to representing real numbers, the IEEE 754 representation can also indicate...

    positive or negative infinity,

    and even when something is not anumber! This is called NaN.

    + 111111112 000000000

    000000000000002

    -

    - 111111112+

    the set of numbers known as denormalizednumbers (including zero),

    +-

    -12610

    -12710

    Example:

    =02

    NaNs arent

    comparable, butthey can bedifferent!

    If this is all zeroes,the float is zero!

  • 8/10/2019 Comic Integer and Float

    7/7

    Floating-Point Numbers:The Great Number Line

    Due to the format of the IEEE-754 standard, the floating-point numbers can be plotted on a number line.In fact, the floating-point numbers are arranged so that they can be incremented like a binary odometer!

    NaN

    + FloatingPoint

    Number

    + DenormalizedNumber

    + 0-

    -

    -

    +-