Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re^2: String to hex

by Anonymous Monk
on Aug 09, 2012 at 13:58 UTC ( #986527=note: print w/replies, xml ) Need Help??


in reply to Re: String to hex
in thread String to hex

It needs to produce 4 lines, not just one

Replies are listed 'Best First'.
Re^3: String to hex
by influx (Beadle) on Aug 09, 2012 at 14:46 UTC

    Eh. Really? OK, well, I would advise against this method, but I was determined to get it working using my original unpack version.. so here goes

    sub str_to_hex { my $str = shift; my @h; for my $s (split(/(....)/, unpack("H*", $str))) { if ($s ne '') { if (length($s) < 4) { $s = ("0" x (4 - int(length($s)))) . $s; } push @h, "0x" . $s; } } push @h, "0x0000" while @h < 4; return @h; } for (str_to_hex("COM7:")) { print $_ . "\n"; }

    This outputs
    0x434f
    0x4d37
    0x003a
    0x0000

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://986527]
help
Chatterbox?
[ambrus]: If you want to typeset a manuscript, you can still do much less work then in the manual typesetting ages and get good formatting.
[ambrus]: All with only cheap modern computers and software.
[ambrus]: Something you can have at home and your corner print shop, without a whole printing press's worth of equipment.
[ambrus]: As for TeX, I'm not trying to discourage anyone from writing carefully beautifully typeset documents, in maths or outside. But most people aren't willing to do that, and will spend only little time about the formatting,
[ambrus]: and try to leave everything else to automated systems without checking how what they write came out format-wise, and for those people, discounting the part about journals with a specific format above,
[ambrus]: just blindly recommending to use LaTeX is a bad idea now.

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (10)
As of 2017-09-26 11:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    During the recent solar eclipse, I:









    Results (293 votes). Check out past polls.

    Notices?