Shortest C \ C++ function to generate -1, 0 ,1 Let a function receive two integers i and j between 0 and 3, it should return the value in position (i,j) in the following 2D array:

1, 0, -1, 0
   1, 0, -1, 0
   0, 1, 0, -1
   0, -1, 0, 1

Shortest code in any variant of C / C++ wins.
40

f(i,j){return~-(2434352710&gt;&gt;8*i+2*j&amp;3);}


A hackish 35 solution (xxd dump):

0000000: 6628 692c 6a29 7b72 6574 7572 6e7e 2d28  f(i,j){return~-(
0000010: 695b 2246 4619 9122 5d3e 3e32 2a6a 2633  i["FF.."]&gt;&gt;2*j&amp;3
0000020: 293b 7d                                  );}


If proper octal escapes are used, it's the same 40 characters:

f(i,j){return~-(i["FF\31\221"]&gt;&gt;2*j&amp;3);}