|
-
Oct 30th, 2002, 05:52 PM
#1
Thread Starter
yay gay
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?
-
Oct 31st, 2002, 12:42 AM
#2
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.
-
Oct 31st, 2002, 09:03 AM
#3
Thread Starter
yay gay
hmm tks anybody has other things to say ? lol
-
Oct 31st, 2002, 09:07 AM
#4
Fanatic Member
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 ^_^
-
Oct 31st, 2002, 06:44 PM
#5
Twos Compliment is what you use, which is what the examples are representing, I think.
-
Oct 31st, 2002, 10:09 PM
#6
PowerPoster
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|