in reply to Re^2: Converting ASCII to Hex
in thread Converting ASCII to Hex
If you have numbers that you want to treat like integers, and they're in the range 0-255, you can put a chr in the chain:
You may also consider printf/sprintf with the X indicator:#!/usr/bin/perl use strict; use warnings; my @values = (0, 1, 5, 25, 100, 200, 255); print join(", ", map { unpack "H*", chr } @values), $/; __END__ 00, 01, 05, 19, 64, c8, ff
Note that this second solution works well with numbers beyond 255. You can also pad with zeroes on the left, just look in the docs for sprintf.#!/usr/bin/perl use strict; use warnings; my @values = (0, 1, 5, 25, 100, 200, 255, 500, 1000); print join(", ", map { sprintf "%X", $_ } @values), $/; __END__ 0, 1, 5, 19, 64, C8, FF, 1F4, 3E8
Flavio
perl -ple'$_=reverse' <<<ti.xittelop@oivalf
|
|---|