unify integer encode/decode implementations