Hi, the correct way: protected static short encodeUnsigned(int positive) { if (positive<32768) { return (short)positive; } else { return (short)(-(65536-positive)); } }