Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 'x' + char
- \x65
- irb> [0x65].pack('U')
- #=> "e"
- irb> "e"[0]
- #=> 101
- irb> "\x#{65}"
- #=> "\x65"
- irb> "\x65".split('')
- #=> ["\", "x", "6", "5"]
- File.open("foo.tmp", "w") do |f|
- f.set_encoding(Encoding::BINARY) # set_encoding is Ruby 1.9
- f.binmode # only useful on Windows
- f.putc "e".hex
- end
- irb(main):002:0> '65'.hex.chr
- => "e"
- irb(main):003:0> ['65'.hex].pack("C")
- => "e"
- irb(main):004:0> ['66', '6f', '6f'].map {|x| x.hex}.pack("C*")
- => "foo"
Add Comment
Please, Sign In to add comment