更新时间:2023-12-02 16:05:52
第一步是了解代码在做什么:
代码似乎将一个字节数组转换为一个十六进制字符串,其中最低字节位于字符串的右侧(它取决于HEX的定义
数组,但我想它只是字符0到9和a到f的映射。
然后你可以在网上搜索一些东西比如perl hex array to string。这样,你会找到像 perl这样的解决方案。整数数组到一个HEX字符串中 - Stack Overflow [ ^ ]。
从我的观点来看,你应该使用一个强大的Perl转换函数: unpack - perldoc.perl.org [ ^ ]。如果输入参数是一个数组,请参阅上面的SO链接。
如果它是包含二进制数据的任何变量,则更简单:
The first step is to understand what the code is doing:
The code seems to convert an array of bytes to a string of hex characters where the lowest byte is on the right side of the string (it depends on the definition of theHEX
array but I guess it is just a mapping to the characters 0 to 9 and a to f).
You can then search the web for something like "perl hex array to string". Doing so, you will find solutions like perl - Convert an array of integer into a string of HEX - Stack Overflow[^].
From my point of view you should use one of the powerful Perl conversion functions: unpack - perldoc.perl.org[^]. If the input argument is an array, see the above SO link.
If it is any variable containing binary data, it is much simpler:
my(
hexString )= unpack(' H *',
hexString ) = unpack( 'H*',
bytes );
bytes );
示例:
Example:
my