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

Answer: 
**Note that this answer was for a previous, different version of the question.**

Your result is wrong for Java.
Please provide some context how you arrived at it (your program, implementation and version of Java).

From the [Java Language Specification](https://docs.oracle.com/javase/specs/jls/se8/html/jls-15.html#jls-15.17.3)

> 
> 15.17.3 Remainder Operator %
>   
> 
> [...]
>   
> 
> The remainder operation for operands that are integers after binary numeric promotion (§5.6.2) produces a result value such that (a/b)\*b+(a%b) is equal to a.
> 

> 
> 15.17.2 Division Operator /  
> 
> [...]  
> 
> Integer division rounds toward 0.
> 

Since / is rounded towards zero (resulting in zero), the result of % should be negative in this case.
To overcome this, you could add `64` (or whatever your modulus base is) to the negative value until it is positive

```
int k = -13;
int modbase = 64;

while (k < 0) {
    k += modbase;
}

int result = k % modbase;

```

The result will still be in the same equivalence class.