-4^2
math
Pic
Location: Stavanger, Norway
Profil3 Views this week: 56
Friends: 13
Written by ali4z on July 20 2008
Viewed 458 times
I often see this math question being asked on basilmarket and elsewhere and it always makes everyone crazy for whatever reason.
Some people say it's supposed to be -(4^2)=-16 as that is how calculators calculate it (and this is the correct way to do it), others say it's supposed to be (-4)^2=16.
Since I am such a computer geek I am going to take a totally different approach to this problem.

Now... In programming languages such as C/C++ the ^ (Caret) operator is not used as power of function, but rather as a bit-wise exclusive OR.
(The power of function can be found in the math.h library as pow())

Bit-wise Exclusive OR (XOR)
A : 1 : 1 : 0 : 0
B : 1 : 0 : 1 : 0
A XOR B : 0 : 1 : 1 : 0

Everyone that knows what a binary number is knows that you can only use 0 and 1 (based on 2), so naturally both the numbers -4 and 2 cannot possibly be binary numbers but rather decimal numbers, and thus must be converted before they can be calculated.

2 is easy to convert: 2 = 10 (or 00000010 in 8-bits)
The -4 might be a bit trickier as how do you write negative binary numbers anyways? You'd think it would be -100, right?
Well you'd be WRONG!

The proper way to convert negative numbers is by writing them with a leading 1 instead of a leading 0. When using 8 bits of the twos-complement numbers, you treat patterns from 00000000 to 01111111 as the whole numbers from 0 to 127 and reserve 1xxxxxxx for negative numbers. A negative number such as -4 is written using the bit pattern for (4-1) with all of the bits complemented (switched from 1 to 0 or 0 to 1). So -4 is complement(4-1) = complement(3) = complement(00000011) = 11111100
So if basically, -4 in decimal is 11111100 in binary when not using numbers higher than 127 or lower than -128 and with 8bits(byte).

The next step would be to actually calculate -4^2
We know ^ means bit-wise XOR, so we write it like this:
11111100
XOR
00000010
Equals
11111110

And the next and last step is to convert it back to decimal.
You can obviously see that the answer has to be negative as the first bit is 1, so you just need to find out what the positive decimal has to be and make it negative. To do this you subtract 01111110 with 00000001 to get 01111101 Then flip it over (invert) to get 0000010. (Note I put the leading 1 to 0). And everyone knows 10 in binary equals 2 in decimal. So the answer has to be -2.

In conclusion: -4^2 = -2



Here is a practical example:

ali4z@masternode:~$ cat test.cpp
#include

using namespace std;

int main() {
int i = -4^2;
cout

Comments
1 - 2
all lies
Bands: metallic, led zeppelin, aerosmith, pink floyd,

this is all so confusing. D:
Blogs: ohbaby.
Bands: sexy stuff.

ME NO HABLAS ESPANOL!

GAHHHH MENTAL MATH OVERDOSE!!!!!
-falls on the ground twitching-
Blogs: Bomb threats
Bands: NONPOINT FTW(and also Fall of troy)

What the fuck.

I skimmed through it and noticed it was supposed to be an elaborate attempt at humor.

Hahaha!

Bands: wat

Nelon2566 said: "What the fuck.

I skimmed through it and noticed it was supposed to be an elaborate attempt at humor.

Hahaha!

"


No, It's serious.
Blogs: -4^2

.____. That's so freaking awesome.

-lerningC#- :c
Blogs: OMGAH.

c.print("LOL WTF.";

WTF, I don't want a smiley face.
Bands: Dead

ali4z said: "
Nelon2566 said: "What the fuck.

I skimmed through it and noticed it was supposed to be an elaborate attempt at humor.

Hahaha!

"


No, It's serious."


Was that a sarcastic remark?
Bands: wat

Nelon2566 said: "Was that a sarcastic remark? "


Nope.
Blogs: -4^2

Your words are funny.
Bands: I'm listening to Chicago. And Caravan.

-4^2=23 nub.

My dick is 18 inches
Bands: Gangster rap yo

I just skipped to the "in conclusion..." Part.

I remember your posts about assembly code. The thing with -4^2 (if you are serious) is that the order of operations and precedence is varies between programming languages and traditional written math. According to the world's traditional order of operations developed many years ago (by some Greek mathematician I presume) the correct answer would indeed be -16. But by the way some programming languages and certain programs read -4^2, it could turn out to be a totally different computation as this respected language's order and precedence differs. For example, if you were to put in -4^2 into microsoft excel and mathematically compute it, you'd see 16 as the answer, which is SOO wrong it's just laughable. It IS made by Microsoft so I would expect errors...
Bands: Army of the Pharoahs, Queen, Gorillaz, etc.


1 - 2

Register / login
You must be a member to reply or post. signup or login