Results 1 to 3 of 3

Thread: SAM and Two's compliment...

  1. #1

    Thread Starter
    Member Benjamin's Avatar
    Join Date
    Nov 2000
    Posts
    48

    Arrow

    Can somebody please explain these to me?

    wednessday in Computer science, the teacher was talking about Sign And Magnitude, and Two's Compliment(for Binary Numbers) but I didn't understand it all the way... could somebody please explain it?



    Thanks,
    Dennis
    -Dennis
    [email protected]
    Ever stop to think, and forget to start again?


    The end justifies the means
    http://www.cfm-resources.com/d/dewrenn
    http://www.phpsquare.com

  2. #2
    Frenzied Member
    Join Date
    Mar 2000
    Posts
    1,089
    Sign and Magnitude's pretty simple, for an n bit number bit n-1 (the highest order bit) represents the sign of the number, and the other bits represent the magnitude, for example

    01111111 represents 127
    11111111 represents -127

    00100111 represents 40
    10100111 represents -40

    00000000 represents 0
    10000000 represents -0

    the trouble with this system is addin numbers becomes quite complicated if one or both is -ve, we're also wasting a number because we can represent + and - 0, so we get the 2s complement system.




    for the 2s complement system every bit represents a value bit 0 represents 1, bit 1 represents 2, bit x represents 2^x, all exept the highest order bit bit n, this represents -2^n. so the value of a number is given by this algorithm


    binary number sxxxxxxx (s and x are bits, s is named
    differently to distinguish it
    from the other bits)

    split into 2 0xxxxxxx
    s0000000


    find the value of the 2 binary numbers

    X
    S

    and subtract X-S

    as the maximum value for x is one less than the value of -S (when bit s is 1) the value of a string of 1s is always -1 and by decrementing x we can represent all -ve numbers down to S.


    this seems like quite a lot of work to get one extra number, plus we can't negate numbers quite so easily, (with SAM we just flip the HO bit to negate the number)

    but it turns out negating numbers isn't that hard

    imagine a binary number T and T's complement !T what is T + !T?

    well for any bit in T the corresponding bit in !T will be the oppisite, so the 2 bits add up to 1 with no carry's, so we get a string of 1s, which is -1


    so we get this

    T + !T = -1

    !T = -1 - T

    !T + 1 = -T


    so to negate a 2's complement number all we have to do is add 1 to it's complement.


    Adding 2's complement numbers is also easy, you just add them like unsigned numbers and amazingly you get the right answer. (it's quite easy to work out why, little chalenge for ya)

    So for the slight difficulty in negating not only do we get an extra -ve number but it makes adding easier and faster, multiplication's about the same.
    If it wasn't for this sentence I wouldn't have a signature at all.

  3. #3

    Thread Starter
    Member Benjamin's Avatar
    Join Date
    Nov 2000
    Posts
    48
    Thanks Sam!
    -Dennis
    [email protected]
    Ever stop to think, and forget to start again?


    The end justifies the means
    http://www.cfm-resources.com/d/dewrenn
    http://www.phpsquare.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width