Guest User

Untitled

a guest
Jun 23rd, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.48 KB | None | 0 0
  1. 'x' + char
  2.  
  3. \x65
  4.  
  5. irb> [0x65].pack('U')
  6. #=> "e"
  7. irb> "e"[0]
  8. #=> 101
  9.  
  10. irb> "\x#{65}"
  11. #=> "\x65"
  12. irb> "\x65".split('')
  13. #=> ["\", "x", "6", "5"]
  14.  
  15. File.open("foo.tmp", "w") do |f|
  16. f.set_encoding(Encoding::BINARY) # set_encoding is Ruby 1.9
  17. f.binmode # only useful on Windows
  18. f.putc "e".hex
  19. end
  20.  
  21. irb(main):002:0> '65'.hex.chr
  22. => "e"
  23.  
  24. irb(main):003:0> ['65'.hex].pack("C")
  25. => "e"
  26. irb(main):004:0> ['66', '6f', '6f'].map {|x| x.hex}.pack("C*")
  27. => "foo"
Add Comment
Please, Sign In to add comment