将十六进制转换为 ascii 字符

2021-12-27 00:00:00 encoding decoding php

是否可以用一个0-9a-zA-Z字符的序列来表示一个十六进制字符(0-9A-F)的序列,所以结果序列更小,可以解码?

Is it possible to represent a sequence of hex characters (0-9A-F) with a sequence of 0-9a-zA-Z characters, so the the result sequence is smaller and can be decoded?

例如:

$hex = '5d41402abc4b2a76b9719d911017c592';
echo $string = encode($hex); // someASCIIletters123
echo decode(string) == $hex; //true

推荐答案

你可以简单地调整我提出的解决方案 此处 使用函数base_convert_arbitrary.

You can trivially adapt the solution I presented here using the function base_convert_arbitrary.

我没有仔细阅读:) Base 16 到 base 62 仍然非常可行,如上所述.

I had not read carefully enough :) Base 16 to base 62 is still very doable, as above.

查看实际操作.

相关文章