There is no ASCII character A0 or B1. If the data is arbitrary bytes, then the following will do:
pack('H*', '4142A0B1')
If the data is actually text (as implied by "ASCII"), you'll need to determine the actual encoding used and use
decode($enc, pack('H*', '4142A0B1'))
(The decode step can be skipped for iso-8859-1.)
For example,
use strict; use warnings; use open ':std', ':locale'; use Encode qw( decode ); for my $enc (qw( ASCII cp850 cp1252 iso-8859-1 UTF-8 )) { my $s = decode($enc, pack('H*', '4142A0B1'), sub { "?" }); printf("%-11s %s\n", "$enc:", $s); }
ASCII: AB?? cp850: ABá▒ Common "western" code page for Windows console cp1252: AB ± Common "western" code page for Windows gui apps iso-8859-1: AB ± Common "western" unix encoding UTF-8: AB??
Note that cp1252 and iso-8859-1 are not equivalent despite producing the same output in this situation.
In reply to Re: convert hex to char fast
by ikegami
in thread convert hex to char fast
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |