Mark because you know almost everything

  • Everlasting
    8 years ago

    Uhmm, do you happen to know what is the purpose of one's complement and two's complement representation? (Data representation in computer system)

    I can't seem to understand it. XD

    P.s. If anyone else knows please free to contribute, I'll appreciate it. If anyone else is like me (lost) but still wishes to add anything else (randomness) to this thread feel free)

  • Saerelune
    8 years ago

    Oh God. Off the top of my head you use it to turn a positive binary number into a negative. It's particularly handy if you're learning assembly language.

    Let's say when you have the number 11 in an 8bit system:
    0000 1011
    (2^0 + 2^1 + 2^3 = 11)

    To turn it into - 11, you first make one's complement by flipping all zeroes to ones and vice versa:
    1111 0100

    Then twos complement is created when you add one to the previous binary number
    1111 0100
    ............... 1
    ------------------ +
    1111 0101

    There's a special way of adding up binary numbers, I hope I did it right but you can look up a binary addition table.

    So if I did this right at 5am I think 1111 0101 is supposed to be - 11 lol

    I think there should be some YouTube videos out there

  • hiraeth
    8 years ago

    ------------------------------------------------
    some binary arithmetic:

    0 + 0 = 0
    0 + 1 = 1
    1 + 1 = 10 (have to carry the 1 over to the left bit and add it)

    1 + 1 + 1 = 11, etc

    ------------------------------------------------
    1's complement is literally inverting the bit's of any given binary representation of a number i.e

    1001 in binary is 9, inverting it (1's complement gives you) 0110. The pitfall with this is that it results in two types of zeroes, a positive and negative zero, which is an issue since zero indicates a null value/lack of a value.

    negative zero is a binary representation with all 1s (1111), and a positive zero is a binary representation with all bits being 0s (0000)

    This is where 2's complement comes into play, you do the same process, invert the bits, and then add 1, this results in there being only one zero.

    In 2s complement zero is depicted as a binary number with all bits being zero.

    Now that you know how to convert from binary to 1s complement and 2s complement, the reasoning behind it is more interesting (well I find it interesting).

    CPUs (computer chips) consist of multiple logic gates, which are the smallest building blocks of any digitial circuit/system.
    It's kinda like how mass is made up of atoms. There are different types of logic gates:

    and gates, nand gates, or gates, nor gates, xor gates, xnor gates, they do different things.

    in "and" gates the truth table is as follows:

    x y | output
    0 0 | 0
    0 1 | 0
    1 0 | 0
    1 1 | 1

    so you can see that it only outputs 1, when both input values are 1 (I know you do some programming and this is equivalent to the "&&" operator in programming languages, it basically means both values must be true (nonempty) in order to output true.

    in "or" gates the truth table is as follows:

    x y | output
    0 0 | 0
    0 1 | 1
    1 0 | 1
    1 1 | 1

    (as long as one input value is true, it outputs a true value).

    The truth table for XOR is as follows:

    in "or" gates the truth table is as follows:

    x y | output
    0 0 | 0
    0 1 | 1
    1 0 | 1
    1 1 | 0

    (so only one value must be true, cannot both be false or true).

    You could read up on the other logic gates (they're pretty easy to understand), but the usage of and gates, xor gates are pretty common, which brings me to why I was explaining these gates and the truth table.

    Computer chips are incapable of subtracting numbers conventionally (they do X + (-Y) instead of X - Y), so by doing the 2s complement you can represent a binary number in negative so that a neat little circuit called a half-adder/full-adder (little digital circuit that uses a xor gate, and a 'and' gate to add numbers)

    The diagram is this: http://volga.eng.yale.edu/uploads/Main/half-adder.png

    Some other usages for 2s complement and 1s complement are: check-sums for IP addresses (it adds up 3 crucial information then does the 1's complement on it and attaches it to the packet of information and the receiving computer can compare the checksum with the original crucial information to ensure that the packet of information has arrived intact.

    Sorry if my explanation is a bit over-kill, just find this stuff fascinating. Let me know if you want to explain or clarify anything I said.

  • Britt
    8 years ago

    I understood literally none of that.

  • Poet on the Piano
    8 years ago

    My reaction
    : - O

    I tip my hat off to all who are responding and adding to this thread... brilliant. Absolutely brilliant!

  • Larry Chamberlin
    8 years ago

    This brings back memories of many years of work I have NO regrets about leaving behind.

  • silvershoes
    8 years ago

    Mark because you know almost everything

    ^10/10 title for this thread

  • Daisy if you do
    8 years ago

    "You could read up on the other logic gates (they're pretty easy to understand),"

    ^^^^
    Easy to understand he said??? WHAT? Yeah easy for Einstein, not for Kay

  • Everlasting
    8 years ago

    Thank you guys, I'll be back to comment when in find some free time.

  • abracadabra
    8 years ago

    Okay, I thought I bested Senyru in the other thread, but now I have sapioenvy.