2014年5月21日 星期三

Convertion between hex string and binary: XXD

Binary to Hex:

# echo 0123456789abcdef0123456789abcdef | xxd
0000000: 3031 3233 3435 3637 3839 6162 6364 6566  0123456789abcdef
0000010: 3031 3233 3435 3637 3839 6162 6364 6566  0123456789abcdef
0000020: 0a   

# echo 0123456789abcdef0123456789abcdef | xxd -g1
0000000: 30 31 32 33 34 35 36 37 38 39 61 62 63 64 65 66  0123456789abcdef
0000010: 30 31 32 33 34 35 36 37 38 39 61 62 63 64 65 66  0123456789abcdef
0000020: 0a                                               .

# echo 0123456789abcdef0123456789abcdef | xxd -i
  0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x61, 0x62,
  0x63, 0x64, 0x65, 0x66, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x0a

Hex string to binary:
# echo 0123456789abcdef0123456789abcdef | xxd    | xxd -r
0123456789abcdef0123456789abcdef

# echo 0123456789abcdef0123456789abcdef | xxd -g1| xxd -r
0123456789abcdef0123456789abcdef

# echo 0123456789abcdef0123456789abcdef | xxd -i | xxd -r -p
0123456789abcdef0123456789abcdef
# echo 0123456789abcdef0123456789abcdef | xxd -r -p | xxd
0000000: 0123 4567 89ab cdef 0123 4567 89ab cdef  .#Eg.....#Eg....

沒有留言: