Stack Exchange
Stack Overflow
Questions
Tags
Users
About
Stack Overflow
Public
Questions
Tags
Users
About
How to convert a backslash hexadecimal string to a binary string in Ruby?
Asked
Apr 11 '14 at 14:43
Active
Apr 11 '14 at 15:02
Viewed
74 times
0
Is there any way other than using 'eval'?
s = '"\xE6\x97\xA5\xE6\x9C\xAC\xE8\xAA\x9E"' puts eval s
ruby
asked Apr 11 '14 at 14:43
Zephyr Dodolee
193
1
7
You can guard against bad strings with a simple regex, in which case an `eval` is a lot less risky. A very similar regex would give you the hex codes direct and you could `unpack` them.
–
Neil Slater
Apr 11 '14 at 14:50
See this answer: http://stackoverflow.com/a/22090177/1120015
–
Uri Agassi
Apr 11 '14 at 15:28
0 Answers
0