Skip to content

Instantly share code, notes, and snippets.

@reecepbcups
Created December 31, 2024 04:32
Show Gist options
  • Save reecepbcups/29c6328099527a1bbe32db2a8010b139 to your computer and use it in GitHub Desktop.
Save reecepbcups/29c6328099527a1bbe32db2a8010b139 to your computer and use it in GitHub Desktop.
# Convert a ETH hex address to decimal and back
# No pre-pended 0x here
# -> [56, 160, 36, 192, 180, 18, 185, 209, 219, 139, 195, 152, 20, 13, 0, 245, 175, 48, 147, 212]
echo -n "["; echo "38a024c0b412b9d1db8bc398140d00f5af3093d4" | sed 's/.\{2\}/\0 /g' | while read -a hex; do
for h in ${hex[@]}; do printf "%d, " "$((16#$h))"; done
done | sed 's/, $/]/'
# convert back to hex
# -> 38a024c0b412b9d1db8bc398140d00f5af3093d4
echo "[56, 160, 36, 192, 180, 18, 185, 209, 219, 139, 195, 152, 20, 13, 0, 245, 175, 48, 147, 212]" | tr -d '[],' | printf "%02x" $(xargs)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment