T
Tim Hunter
Since nobody else has any Ruby to talk about today...
My gut feel is that this should be 2 or 3 lines of code but for some
reason I'm missing the trick.
I need a script that converts pairs of hex digits into their decimal
equivalents. Suppose the script accepts a single argument, a string
composed of hex digits, either upper- or lower-case, or both, possibly
with embedded blanks. For the sake of argument let's say that there's
always going to be at least 1 pair but never more than, oh, 20 pairs (or
as many as can easily be typed on a command line).
The script should remove any embedded blanks from the argument, then go
through the string left-to-right. For each pair of hex digits, display
the value of the pair as a 3-digit decimal number, separated with a
backslash.
So, for example,
ruby hex2dec.rb "f0 d7e2 28" => \240\215\226\040
Ideas?
My gut feel is that this should be 2 or 3 lines of code but for some
reason I'm missing the trick.
I need a script that converts pairs of hex digits into their decimal
equivalents. Suppose the script accepts a single argument, a string
composed of hex digits, either upper- or lower-case, or both, possibly
with embedded blanks. For the sake of argument let's say that there's
always going to be at least 1 pair but never more than, oh, 20 pairs (or
as many as can easily be typed on a command line).
The script should remove any embedded blanks from the argument, then go
through the string left-to-right. For each pair of hex digits, display
the value of the pair as a 3-digit decimal number, separated with a
backslash.
So, for example,
ruby hex2dec.rb "f0 d7e2 28" => \240\215\226\040
Ideas?