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

Thread: ^ operator

  1. #1
    Regular Coder
    Join Date
    Apr 2010
    Posts
    163
    Thanks
    3
    Thanked 25 Times in 25 Posts

    ^ 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.

  • #2
    Regular Coder
    Join Date
    Jan 2004
    Location
    USA
    Posts
    364
    Thanks
    12
    Thanked 6 Times in 6 Posts
    Googling "javascript caret operator" returns this.
    Running Windows 7 x64

  • #3
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,980
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    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 ~.
    Last edited by Fou-Lu; 08-25-2010 at 08:30 PM.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • 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
    •