From: perl-win32-users-boun...@listserv.activestate.com 
[mailto:perl-win32-users-boun...@listserv.activestate.com] On Behalf Of Greg 
Aiken
Sent: 23 November 2010 21:44
To: perl-win32-users@listserv.ActiveState.com
Subject: how to best convert an array containing hexadecimal values to 
asciivalue?

> and im kind of lost with pack...  ive unsuccessfully tried...
>
> $ascii_string = pack("H*", @hex_array) and 
> $ascii_string = pack("h*", @hex_array) 
>
> but neither yields the proper output.
>
> I know I could write an ultra low level code that directly converts each hex 
> byte to decimal, then call chr 
> with the decimal value, but certainly that's 'too much work' in perl.
>
> any help would be appreciated.
>
> it would be as if were starting with 
>
> @hex_array = ('5c','00','3f','00','3f','00','5c','00','53','00',...);

Your are not too far out with pack, as it happens, but you haven't got it quite 
right. Your template only unpacks the first string in the array. Try:

$ascii_string = pack("(H2)*", @hex_array);

Have another read through 'perldoc -f pack'. I usually have to whenever I use 
it.

Also, I notice that all of your characters seem to be followed by a null byte. 
Are these perhaps 16 bit characters, or will you strip the null bytes out at 
some point?

-- 
Brian Raven 
 
Please consider the environment before printing this e-mail.

This e-mail may contain confidential and/or privileged information. If you are 
not the intended recipient or have received this e-mail in error, please advise 
the sender immediately by reply e-mail and delete this message and any 
attachments without retaining a copy.

Any unauthorised copying, disclosure or distribution of the material in this 
e-mail is strictly forbidden.
_______________________________________________
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to