简体   繁体   English

在 perl 中将两字节的十六进制字符串转换为字符

[英]Convert two-byte hex string to char in perl

I have a string of two-byte hex characters and I'd like to convert them to an ascii or unicode string.我有一个两字节的十六进制字符字符串,我想将它们转换为 ascii 或 unicode 字符串。 The string can have a variable length.字符串可以具有可变长度。 Input:输入:

$hex_string="003400300030"

Desired output:期望的输出:

$char_string="400"
use Encode qw( decode );

my $char_string = decode('UTF-16be', pack('H*', $hex_string));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM