Minus, Plus, Times, Exponentiation? This is a CMC (chat mini challenge) that I posted in our chatroom, The Ninteenth Byte, a bit ago.

The Challenge

Given a positive integer x, depending on the last 2 bits of x, do the following:

x &amp; 3 == 0: 0
x &amp; 3 == 1: x + x
x &amp; 3 == 2: x * x
x &amp; 3 == 3: x ^ x (exponentiation)


Input/Output

Single Integer -&gt; Single Integer  


A trailing newline is permitted in the output. No other whitespace is permitted.

Testcases

input       output
    1            2
    2            4
    3           27
    4            0
    5           10
    6           36
    7       823543
    8            0
    9           18
   10          100
   11 285311670611
   12            0


This is a code-golf challenge, so the shortest code wins!
Jelly, 8 bytes

ị“+×*_”v


Try it online!

How it works

Firstly, notice that x&amp;3 is equivalent to x%4, where % is modulo. Then, since Jelly uses modular indexing (a[n] == a[n+len(a)]), so we don't even need to deal with that.

Then:


If x%4==0, return x_x (subtraction) (for consistency);
If x%4==1, return x+x;
If x%4==2, return x×x(multiplication);
If x%4==3, return x*x(exponentiation)


Note that Jelly uses 1-indexing, so the subtraction "_" is moved to the end.

ị“+×*_”v  example input: 10
ị“+×*_”   index 10 of the string “+×*_”, which gives "×"
       v  evaluate the above as a Jelly expression,
          with 10 as the argument, meaning "10×" is the
          expression evaluated. The dyad "×" takes the
          second argument from the only argument, effectively
          performing the function to itself.