[英]Convert number to HEX in perl
I need to convert a number to hex in perl. 我需要在perl中将数字转换为十六进制。 I'm using the following simple code:
我使用以下简单代码:
my $n = 10;
print sprintf("%X", $n);
That will output: A That's correct, but I need always 2 bytes like: 0A 那将输出: A这是正确的,但我总是需要2个字节,如:0A
So for example: 90 will show 5A - 6 will show 06 - 10 will show 0A 例如:90将显示5A - 6将显示06 - 10将显示0A
How can I do that? 我怎样才能做到这一点?
sprintf("%02X", $n)
\n
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.