How to print a variable in reversed byte order in Perl?

Posted by jth on Stack Overflow See other posts from Stack Overflow or by jth
Published on 2010-06-03T15:11:07Z Indexed on 2010/06/03 15:14 UTC
Read the original article Hit count: 179

Filed under:
|

Hi, I'am trying to convert the variable $num into its reverse byte order and print it out. This is what I have done so far:

my $num=0x5514ddb7;
my $s=pack('I!',$num);
print "$s\n";

He prints it out as some non-printable characters and in a hex editor it looks right, but how can I get it readable on the console?

Already tried

 print sprintf("%#x\n",$s);

but he complains about an non-numeric argument, so I think pack returns a string. Any ideas how can I print out `0xb7dd1455 on the console, based on $num?

© Stack Overflow or respective owner

Related posts about perl

Related posts about pack