in reply to Casting numbers

You bit-negated a 32 bit value - of course printf gave you all the significant digits. Only you can know which digits are safe to throw away.

I recommend the following:

perl -e '$a = 127; printf "original:%04x, bit-negative version:%04x\n" +, $a, (~$a)&0xffff;' original:007f, bit-negative version:ff80