Regarding two's complement

I've come to the conclusion that 2's complement is black magic. Bare with me

Lets take a random signed binary 8-bit integer. Say 5.

00000101

now lets make it negative using twos complement

first flip the bits.

11111010

then add 1

11111011

you want proof? if we add the two together we should get 0

00000101 <- 8-bits only
+11111011 <- 8-bits only
----------
00000000 <- 8-bits only
SORCERY!!!!

how bout the integer -128

10000000

01111111
+ 1
---------
10000000

WITCHCRAFT. -128 is the same as 128 D:

If you can give me a better reason for twos complement to work other than magic. let me know.

do not take me seriously. this was all in good fun. I know for a fact it works due to the hardware gnomes that make it work.
Grrr.

-Albatross
Hey now, I presented this to my computer science teacher in essay format ( a lot more formally written then it is here) as extra credit and he gave me an F for funny. that's what F stands for right...right? T_T
2's complement makes sense because it is transparent about numerical wrapping.

Consider a machine where the maximum bitwidth is 8 bits. With unsigned numbers, going over 255 causes values to wrap:

0x90 + 0x90 = 0x20 (really 0x120, but because only 8 bits can be represented, the 1 gets dropped)

consider now:

0x05 + 0xFF = 0x04 (again ... really 0x104, but the 1 is dropped)

so effectively, adding 0xFF is the same as subtracting 1.
what's more, adding 0xFE is the same as subtracting 2
and so on.

That's really all there is to it.

It makes sense to implement this in hardware because you don't have to care about sign in order to do addition or subtraction. Addition is the same for signed or unsigned numbers, and the same circuitry can be used in either case.
Last edited on
I was actually aware of this but felt like posting some thing moderately humorous. But thank you for posting how it ACTUALLY works, so that people who are new to computer theory in general dont get confused by my asinine post.
Well I wasn't sure or not. On one hand you said "if you can give a better reason do so". On the other hand you said "dont' take me seriously"

In my head I was thinking "does he really want an answer or not?"

Then I thought that taking you seriously would mean to think you really thought it was witchcraft/black magic/computer gnomes. And I didn't think you thought that, so I wasn't taking you seriously. But that still left the "does he really want an answer" question on my plate.


Anyway whatever. XD
Now do it again for floating point.
no thanks. Floating point really is black magic.
I actually dont know how those work in binary. I can do fixed point operations. But i have yet to learn floating point. Incidentally i asked by professor about them today. He said he hadnt planned on getting into them but was willing to explain them to me if I could stay after class. I had a previous arrangement i had to attend to so I couldn't.
Eh? Do it again for floating point?

...That's just plain boring. How about we just get in a circle and start throwing invocations at the virgin in the middle of the pentagram EDIT: followed by a blood sacrifice, a ritual slaughtering of a llama and the tossing of three lit black candles into warehouse full of high explosives, with the virgin?

EDIT2: Bad idea. We could get an infection during the blood sacrifice, and for invoking demons, two's complement for floating points is better, I guess.

-Albatross
Last edited on
That will only swap the signs for a fixed point number.
Oh, man. Fixed point arithmetic is so awesome I once shouted "and not sixty-five thousand five hundred and thirty-five" and some poor sap's skull got turned inside out.
Last edited on
I actually dont know how those work in binary. I can do fixed point operations. But i have yet to learn floating point. Incidentally i asked by professor about them today. He said he hadnt planned on getting into them but was willing to explain them to me if I could stay after class. I had a previous arrangement i had to attend to so I couldn't.
I'll be waiting for your Floating Point Magic.
Floating point is a b**** to compute on paper. That said, I use it every day to impede suicide bombers by blowing them up with it.

-Albatross

P.S.- Seriously, though. It's a right pain.
Seraphimsan wrote:
WITCHCRAFT. -128 is the same as 128 D:


Well yeah... the range is -128 to 127, so 128 would wrap around...
Sadly, the same applies if you'd take 512-bit signed integers;
-115792089237316195423570985008687907853269984665640564039457584007913129639936 equals 115792089237316195423570985008687907853269984665640564039457584007913129639936!

I call witchcraft, burn the evil-doers, who ever that may be!


Edit:
P.S.: Random threads / posts, hail, hail! Long may they live.
Last edited on
I'm actually interested in floating-point black magic. Anyone know how it works?
F*ckin' miracles.
^agreed.
Topic archived. No new replies allowed.