Skip to content

Exploring Binary Representation with hexedit

Delve into the hexadecimal representation of text with hexedit, a versatile tool for examining binary data. This script demonstrates how to convert text to hexadecimal format in Bash, providing insights into binary encoding

How this works

Command Description
s=$(echo "this is just some text" rev)
hex="" Creates an empty variable hex to store the hexadecimal values.
for (( i=0; i<${#s}; i++ )) loops through each character in the s string.
hex+="\((printf "%02x" "'\)")" Converts each character to its hexadecimal value using the printf command and appends it to the hex variable.
echo ${hex^^} Prints the hex variable in uppercase (uppercase hexadecimal values).
#!/bin/bash

s=$(echo "this is just some text" | rev)
hex=""
for (( i=0; i<${#s}; i++ )); do
  hex+="$(printf "%02x" "'${s:i:1}")"
done

echo ${hex^^}