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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.