Created
July 6, 2011 05:18
-
-
Save dcrosby42/1066617 to your computer and use it in GitHub Desktop.
Example uses of HexString, extracted from README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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