These are supposed to represent four hex values. I want a string each of
whose "characters" (bytes) is one of those hex values, in order, like
this: "\002S\000\f"
I can transform the given string like this:
s = "0x0253000c"
output = ""
s = s[2..-1]
s.split(//).each_slice(2) do |ss|
output << ss.join.hex.chr
end
p output # => "\002S\000\f"
Great, but this seems idiotic. There must be some simple neat way that
I'm not seeing. Could you tell me what it is? Thx - m.
Perfect; I had tried unpack but not pack. So this will work for the
strings I am getting:
output = [s[2..-1]].pack("H*")
Thanks! m.
···
botp <botpena@gmail.com> wrote:
On Sun, Jul 22, 2012 at 10:42 AM, Matt Neuburg <matt@tidbits.com> wrote:
> s = "0x0253000c"
> output = ""
> s = s[2..-1]
> s.split(//).each_slice(2) do |ss|
> output << ss.join.hex.chr
> end
> p output # => "\002S\000\f"
>
> Great, but this seems idiotic.
well, i dont find that "idiotic" so to speak...
but try this eg,