May 23, 2002, 8:06 AM
Post #4 of 4
Well, in your original post you asked how to convert 2-digit hex values to ASCII. Also, you wanted to convert one file to another. Now you have a 3-digit hex value stored in a scalar and want to convert it to a scalar holding the corresponding ASCII character. Except for the fact of converting hex to ASCII, these are completely different tasks.
Re: [Troy] Converting from Hex to Char
[In reply to]
However, what you want to do can be accomplished with the chr and hex functions:
$data_hex = '057';
$data_ascii = chr hex $data_hex;
The [url=http://www.perldoc.com/perl5.6.1/pod/func/hex.html]hex function interprets a string as a hexadecimal value and returns its decimal representation. The [url=http://www.perldoc.com/perl5.6.1/pod/func/chr.html]chr function then takes that decimal value and converts it to the corresponding ASCII character. You can follow the links to get to the online manpages of these function.
Hope this helps.
At last with an effort he spoke, and wondered to hear his own words, as if some other will was using his small voice. "I will take the Ring," he said, "though I do not know the way."