Signed number grief.

That's not the mask I wanted. I wanted this one:const long deviceMask = -(1 << (deviceWordLength - 1));The mask isolates the sign bit for testing, and extends the sign bit when the sign bit is set. It needs to be as long as the type of the input, which is int in this case, but it doesn't need to be longer.