Post Reply 
negative number raised to even power
05-05-2015, 05:17 AM
Post: #45
RE: negative number raised to even power
In C/C++, ^ is exclusive or (xor). In C (but not in C++), from C99 onwards, when using the alternative spellings iso646.h header, xor is expanded to ^.

With 2's complement representation of negative numbers:
* the binary representation of -1 is the pattern of 1 (0b11...111 in GCC and Clang for years, C++14 made the 0b syntax standard);
* the binary representation of -2 is 0b11...110;
* the binary representation of 2 is 0b00...010;
* the binary representation of (-2)^2 is therefore 0b11...100, i.e. -4.
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
negative number raised to even power - DrD - 04-25-2015, 11:24 AM
RE: negative number raised to even power - debrouxl - 05-05-2015 05:17 AM



User(s) browsing this thread: 15 Guest(s)