fixed encode function for VarInt