M
Michael W. Ryder
Is there a bitwise and for strings that I am missing? I tried the
documentation and Google with no luck. I coded a simple method to
handle this, it obviously needs more error checking, but don't want to
reinvent the wheel if not necessary.
def AND(s, m)
t = s.dup
for i in 0...(s.size <= m.size ? s.size : m.size)
t = (s & m).chr
end
return t
end
On a related note, is there any way to create a string from a hex number
other than separating each two digits and using .chr to convert them to
a number and adding them to the string? If I have a string such as
0x7FFFFFFFFFFF I have to use something like str1 = 0x7F.chr followed by
5 str1 << 0xFF.chr which seems to be unnecessarily clumsy.
documentation and Google with no luck. I coded a simple method to
handle this, it obviously needs more error checking, but don't want to
reinvent the wheel if not necessary.
def AND(s, m)
t = s.dup
for i in 0...(s.size <= m.size ? s.size : m.size)
t = (s & m).chr
end
return t
end
On a related note, is there any way to create a string from a hex number
other than separating each two digits and using .chr to convert them to
a number and adding them to the string? If I have a string such as
0x7FFFFFFFFFFF I have to use something like str1 = 0x7F.chr followed by
5 str1 << 0xFF.chr which seems to be unnecessarily clumsy.