Skip to content

Instantly share code, notes, and snippets.

@solomonhuang
Created September 4, 2012 13:09
Show Gist options
  • Save solomonhuang/3621010 to your computer and use it in GitHub Desktop.
Save solomonhuang/3621010 to your computer and use it in GitHub Desktop.
hexdump convert binary to c array data
$ dd if=/dev/urandom bs=1 count=160 | hexdump -v -e '15/1 "0x%02X, " 1/1 " 0x%02X,\n"'
160+0 records in
160+0 records out
160 bytes (160 B) copied, 0.000507955 s, 315 kB/s
0xB3, 0x4C, 0xD7, 0x9B, 0xC4, 0x83, 0x7C, 0x92, 0xDE, 0xF5, 0x63, 0xBA, 0xAB, 0xCF, 0xDE, 0x13,
0x7F, 0xCE, 0x9D, 0xE9, 0x9F, 0xF8, 0xA2, 0xCB, 0x52, 0x6A, 0xD7, 0xDE, 0xD8, 0x12, 0xAC, 0x71,
0x1B, 0x5E, 0xF2, 0x2E, 0x1C, 0x82, 0x24, 0x24, 0xA2, 0x5D, 0x27, 0x90, 0xE4, 0xDC, 0x21, 0xF3,
0xAB, 0x9F, 0xD6, 0x1A, 0xDE, 0xFC, 0xA3, 0xDC, 0x49, 0xA2, 0xEF, 0xF2, 0x95, 0xCB, 0x8A, 0xE2,
0x6F, 0xD5, 0x2E, 0x48, 0x2B, 0x4D, 0x35, 0xEC, 0x62, 0x24, 0x75, 0xEB, 0xCF, 0x26, 0x57, 0xB2,
0x56, 0x65, 0xDF, 0x25, 0xA9, 0xB1, 0xD9, 0x78, 0x7F, 0x76, 0xB2, 0xF4, 0x57, 0xAD, 0xDC, 0xCC,
0x8D, 0xB0, 0x02, 0x6C, 0x39, 0xDB, 0xEE, 0x44, 0x34, 0xF8, 0x83, 0x17, 0xE1, 0x38, 0x57, 0xA0,
0xEA, 0xAE, 0x8B, 0x2C, 0xF8, 0xEB, 0x30, 0xE3, 0xB3, 0x6B, 0x37, 0xB2, 0xF2, 0x20, 0xDF, 0xA5,
0xF2, 0x09, 0x7F, 0xCF, 0x1A, 0xF4, 0xB9, 0x58, 0xBD, 0x58, 0xC8, 0x46, 0xC4, 0xCF, 0x39, 0x92,
0xA6, 0x81, 0xAE, 0xB1, 0xEA, 0xB5, 0xC7, 0x12, 0x6D, 0x57, 0x64, 0xB6, 0x51, 0x2F, 0x4B, 0x12,
$ dd if=/dev/urandom bs=1 count=160 | hexdump -v -e '7/1 "0x%02X, " 1/1 " 0x%02X,\n"'
160+0 records in
160+0 records out
160 bytes (160 B) copied, 0.000503906 s, 318 kB/s
0x89, 0xA9, 0x16, 0xD5, 0x87, 0x7D, 0xA8, 0x9B,
0x23, 0x2B, 0xA8, 0x33, 0x54, 0xC1, 0x66, 0x41,
0x25, 0x89, 0x95, 0x72, 0xA7, 0xDD, 0xE1, 0x6A,
0x4B, 0xB4, 0xD5, 0xA9, 0xE7, 0x9B, 0xE0, 0xA4,
0x08, 0x6C, 0x0A, 0x7C, 0xB7, 0x81, 0x28, 0xE0,
0x83, 0x57, 0x9F, 0xDE, 0x9E, 0x1C, 0xBA, 0xD8,
0xB8, 0xF6, 0xFF, 0x35, 0x18, 0x95, 0x04, 0x5C,
0x31, 0x1C, 0x61, 0x25, 0xAD, 0x29, 0xED, 0xE6,
0x49, 0x85, 0x14, 0x96, 0x8E, 0x7E, 0x1F, 0xFB,
0x86, 0x41, 0x46, 0x3C, 0x3C, 0xB7, 0xF3, 0x8A,
0x8F, 0x6E, 0x49, 0x2E, 0xA9, 0x4D, 0xE5, 0xC1,
0x32, 0x53, 0xAB, 0x0C, 0x2B, 0xD9, 0xCA, 0x16,
0x60, 0x7D, 0x7E, 0x0B, 0x0B, 0x39, 0x1B, 0x77,
0x8B, 0x3D, 0xFA, 0xD2, 0xB2, 0x22, 0x3A, 0xC2,
0xB7, 0x62, 0xD6, 0xB4, 0x9D, 0x6A, 0x39, 0xAA,
0xA3, 0xE2, 0x2E, 0x1B, 0x6F, 0x82, 0x0D, 0xD1,
0x45, 0xC2, 0x94, 0x03, 0x6B, 0x04, 0x17, 0x41,
0xE2, 0x28, 0x9E, 0xEC, 0xC4, 0x66, 0xDC, 0xB1,
0xB8, 0x74, 0xF7, 0xF1, 0x87, 0x4A, 0x8B, 0xD1,
0x9D, 0x5F, 0x73, 0x3C, 0x87, 0x8A, 0xBC, 0x01,
hexdump -v -e '7/1 "0x%02X, " 1/1 " 0x%02X,\n"' # 8 cols.
hexdump -v -e '15/1 "0x%02X, " 1/1 " 0x%02X,\n"' # 16 cols.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment