Skip to content

Instantly share code, notes, and snippets.

@dcrosby42
Created July 6, 2011 05:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dcrosby42/1066617 to your computer and use it in GitHub Desktop.
Save dcrosby42/1066617 to your computer and use it in GitHub Desktop.
Example uses of HexString, extracted from README.md
# Load HexString and automatically extend String:
require 'hex_string'
# Convert data to human-readable hex tuples:
>> "hello".to_hex_string
=> "68 65 6c 6c 6f"
# Compact a hex string into its data equivalent:
>> "77 6f 72 6c 64".to_byte_string
=> "world"
# (#to_byte_string is space and case-insensitive:)
>> "776F726C64".to_byte_string
=> "world"
# Peek at the first 4 bytes of an executable on OS X:
>> File.read("/bin/ls")[0..3].to_hex_string
=> "ca fe ba be"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment