encode and encodeHex ported