Hexadecimal to decimal or vice versa with printf

From Brandonhutchinson.com

Revision as of 22:16, 16 October 2007 by Hutch (Talk | contribs)
(diff) ←Older revision | Current revision (diff) | Newer revision→ (diff)
Jump to: navigation, search
  • Hexadecimal to decimal:
$ printf "%02X\n" decimal number
  • Decimal to hexadecimal:
$ printf "%d\n" hexadecimal number

Examples

  • Convert 1024 to hexadecimal.
$ printf "%02X\n" 1024
400
  • Convert 0x400 to decimal.
$ printf "%d\n" 0x400
1024
Personal tools