Question: Am I doing modulus wrong? Because in Java `-13 % 64` evaluates to `-13` but I want to get `51`.

Answer: 
Both definitions of modulus of negative numbers are in use - some languages use one definition and some the other.

If you want to get a negative number for negative inputs then you can use this:

```
int r = x % n;
if (r > 0 && x < 0)
{
    r -= n;
}

```

Likewise if you were using a language that returns a negative number on a negative input and you would prefer positive:

```
int r = x % n;
if (r < 0)
{
    r += n;
}

```
Your answer is in wikipedia:
[modulo operation](http://en.wikipedia.org/wiki/Modulo_operation)

It says, that in Java the sign on modulo operation is the same as that of dividend. and since we're talking about the rest of the division operation is just fine, that it returns -13 in your case, since -13/64 = 0. -13-0 = -13. 

EDIT: Sorry, misunderstood your question...You're right, java should give -13. Can you provide more surrounding code?