Skip to content

Instantly share code, notes, and snippets.

@masapico
Created December 17, 2013 16:31
Show Gist options
  • Select an option

  • Save masapico/8007846 to your computer and use it in GitHub Desktop.

Select an option

Save masapico/8007846 to your computer and use it in GitHub Desktop.
# Display bytes in String
puts "- utf-8 ------------------------------"
'あ'.bytes { |b| puts "#{b.to_s(16)} => #{sprintf("%#010b", b)}" }
puts "- sjis ------------------------------"
'あ'.encode("Windows-31J").bytes { |b| puts "#{b.to_s(16)} => #{sprintf("%#010b", b)}" }
puts "- utf-16le ---------------------------"
'あ'.encode("utf-16le").bytes { |b| puts "#{b.to_s(16)} => #{sprintf("%#010b", b)}" }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment