Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Text to hex

0 views
Skip to first unread message

Mark Wagner

unread,
May 10, 2008, 12:14:04 AM5/10/08
to begi...@perl.org
Given a string of text, how do I convert it to a string of hexadecimal
values? For example, given the string "Hello", I want the string "48
65 6C 6C 6F".

--
Mark

John W. Krahn

unread,
May 10, 2008, 1:02:36 AM5/10/08
to Perl Beginners

$ perl -le'my $string = "Hello"; print unpack "H*", $string'
48656c6c6f


John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order. -- Larry Wall

Mark Wagner

unread,
May 10, 2008, 3:54:23 AM5/10/08
to Perl Beginners
On Fri, May 9, 2008 at 10:02 PM, John W. Krahn <kra...@telus.net> wrote:
> Mark Wagner wrote:
>>
>> Given a string of text, how do I convert it to a string of hexadecimal
>> values? For example, given the string "Hello", I want the string "48
>> 65 6C 6C 6F".
>
> $ perl -le'my $string = "Hello"; print unpack "H*", $string'
> 48656c6c6f

Thanks. Is there a good explanation of "unpack" somewhere?

--
Mark

John W. Krahn

unread,
May 10, 2008, 7:39:42 AM5/10/08
to Perl Beginners

perldoc perlpacktut

0 new messages