byte array

Printing out a string as a byte array and corresponding hexadecimal

Blog tags: 

Here is a quick script that is pretty handy!

#!/bin/bash
STR="Its a small world afterall"
CNT=$(wc -c <<< $STR})
TMP_CNT=0

printf "Char Hex\n"

while [ ${TMP_CNT} -lt $[${CNT} -1] ]; do
  printf "%-5s 0x%-2X\n" "${STR:$TMP_CNT:1}" "'${STR:$TMP_CNT:1}"
  TMP_CNT=$[$TMP_CNT+1]
done

Which will output the following:

Subscribe to RSS - byte array