Code:
public static long unsign(long value, int amount)
{
// 1 = byte, 2 = short, 3 = tribyte, 4 = int, 8 = long (overflow)
return value &~ (0xFFFFFFFFFFFFFFFFL << (64 - (8 * (8 - amount))));
}
public static long sign(long value, int amount)
{
long unsigned = unsign(-1, amount);
long signed = (unsigned & (0x7FFFFFFFFFFFFFFFL) << 1) >> 1;
if (value > signed)
{
return value - (unsigned + 1);
}
return value;
}
Just thought it was an interesting idea. I got the idea of signing from the stream class in the client. Any better method to sign something unsigned?