all lies
Bands: metallic, led zeppelin, aerosmith, pink floyd,
+Most Recent Blogs
| Written by ali4z on July 20 2008
Viewed 462 times
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
all lies
Bands: metallic, led zeppelin, aerosmith, pink floyd,
07/20/08
Guilds: MoonStruck Groups: BasilMarket's Comic Makers!, Crazy Spammers, Marvel Maniacs GAHHHH MENTAL MATH OVERDOSE!!!!!
-falls on the ground twitching-
Blogs: Bomb threats
Bands: NONPOINT FTW(and also Fall of troy)
07/22/08
Nelon2566
Groups: Alliance of the Banned From Basil Market, AznSealism, Bannedstory Animations What the fuck.
I skimmed through it and noticed it was supposed to be an elaborate attempt at humor. Hahaha!
Blogs: Ew, suspended again
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
07/24/08
Nelon2566
Groups: Alliance of the Banned From Basil Market, AznSealism, Bannedstory Animations 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?
Blogs: Ew, suspended again
Bands: wat
Nelon2566 said: "Was that a sarcastic remark? Nope.
Blogs: -4^2
07/26/08
Drizzly
Groups: Alliance of the Banned From Basil Market, Basil IRC! :), Basil Market's Top Users ;) Your words are funny.
Blogs: Epic thread : commence.
Bands: I'm listening to Chicago. And Caravan.
07/30/08
Kerpail
Groups: Alliance of the Banned From Basil Market, Basil Market's Top Users ;), Basil War Veterans My dick is 18 inches
Blogs: Redwings is God
Bands: Gangster rap yo
08/11/08
iimaplers
Groups: 1337, Alliance of the Banned From Basil Market, Basil Market's Top Users ;) 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.
09/01/08
StrikeFreedm
I think you just exploded my brain.
Bands: How many times do I have to repeat myself?
Register / login
| |