Skip to content

Instantly share code, notes, and snippets.

@itsmikita
Created October 15, 2023 15:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save itsmikita/2aa9c434344e987a5e438eb4356c5a7e to your computer and use it in GitHub Desktop.
Save itsmikita/2aa9c434344e987a5e438eb4356c5a7e to your computer and use it in GitHub Desktop.
Convert Decimals to Hexadecimals and backwards in Shell
#!/bin/bash
# convert decimal (0-255) to hexadecimal (00-FF)
function d2h() { printf "%X\n" $1 }
#!/bin/bash
# convert hexadecimal (00-FF) to decimal (0-255)
# don't forget to prepend "0x"
function h2d() { printf "%d\n" $1 }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment