Results 1 to 6 of 6

Thread: Binary and negative numbers...

  1. #1

    Thread Starter
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729

    Binary and negative numbers...

    hmmm...how do i represent binary negative numbers?

    for example...if i go to windows calculator and write -30 in decimal and then turn it to bin ill get a 1111111111111111111111111111111111111111111111111111111111100010

    then if i turn this bin to decimal ill get a 18446744073709551586..hmmm...im getting confused..any help?

  2. #2
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,803
    There is no way (no standard way) that I know of....

    The windows Calculator returns back 18446744073709551586 because the computer actually stores all numbers as unsigned... the signed is only for us (humans), it's just a diferent representation of what the computer has in the memory...

    Anyways... try this
    First convert 30 to binary, you will get 11110 witch is actually 0000000000000000000000000000000000000000000000000000000000011110
    then convert -30 -> 1111111111111111111111111111111111111111111111111111111111100010

    and you'll see that the 11110 is inverted in the second one... it's called the 2's complement (or something like that), that consists of a binary NOT then minus one... (i hope i'm right)

    Once the number is converted in binary, to the calculator thinks the value is unsigned, and then it will convert back to unsigned....

    BUT... if you click on +/- to 18446744073709551586 to make it signed, and THEN you convert it back to binary, you will see that you get the same output as 30... ( 11110 )

    I hope I did not confuse you more...
    Last edited by CVMichael; Oct 31st, 2002 at 12:48 AM.

  3. #3

    Thread Starter
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    hmm tks anybody has other things to say ? lol

  4. #4
    Fanatic Member scr0p's Avatar
    Join Date
    Oct 2002
    Location
    VA
    Posts
    720
    To convert binary to negative, you invert all the 1 and 0's and add 1, Take this example:

    00011 is positive, negative, we would invert, 11100, then add 1, 11101 <- that should be negative, i think ^_^

  5. #5

  6. #6
    PowerPoster
    Join Date
    Aug 2001
    Location
    new jersey
    Posts
    2,904
    the decimal equivalent of 2's complement is 10's complement. If we could only use the numbers from 0 to 99 but we wanted to be able to represent negative numbers what would we do?

    well, one thing we could do is decide that our number range was really -49 to +50 and that any number that looks bigger than 50 is actually a 10's complement number, so for example 71 doesn't represent 7 tens and a unit, it represents -39. we get the 39 by takiing 100-71.

    I KNOW all this is confusing, but if you want to understand how computer number systems work, understanding 2's complement is necessary and since most of you think in decimal rather than binary (I personally think in binary, but usually use hex shorthand), it's easier to look at how the ten's complement works and then extrapolate it to 2's complement. Or maybe not.

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