Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.

1. ## ^ operator

i was using my JavaScript console as a calculator, and i accidentally used "^" for exponents.
the statement did not return a syntax error, but a number, after doing some more ^ operations i can't see the relation between the numbers i use and the answer it gives me.

• Googling "javascript caret operator" returns this.

• Its simply a bit XOR.
It returns a result where each bit in the left side that matches on the right side is inverted. Just on a nibble calculation since I don't want to type all the 0's.
5 = 0101
4 = 0100

5 ^ 4 = 1
The 'leftmost' bit in the above (2^(3-1), where this one is actually the exponent) is 1 in both the 5 and the 4, so its inverted to 0. The rightmost one (2^(1-1)) is 1 only in the 5 and not in the 4, so it remains untouched. Simple as that.

Edit:
Dang, beaten. That's a good link too, all its missing is the not (since I don't think derivatives like NAND exist in most languages), which is simply a unary ~.

• ## Users who have thanked Fou-Lu for this post:

gizmo1650 (08-25-2010)

•

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•