查询如何解压缩打包的二进制数据

时间:2019-06-13 04:33:59

标签: perl pack unpack

我使用以下代码打包了二进制数据: 我的$ binarydata。= pack(“ H2”,$ no);

这给了我一些不是可读格式的二进制数据。

我需要获取此二进制数据,并使用unpack转换回ascii。 任何帮助将不胜感激

1 个答案:

答案 0 :(得分:2)

的倒数

my $single_byte_str = pack("H2" , $two_hex_digits);
   or
my $single_byte_str = pack("C" , hex($two_hex_digits));
   or
my $single_byte_str = chr(hex($two_hex_digits));

my $two_hex_digits = unpack("H2" , $single_byte_str);
  or
my $two_hex_digits = sprintf("%02x", unpack("C" , $single_byte_str));
  or
my $two_hex_digits = sprintf("%02x", ord($single_byte_str));
相关问题