Hexadecimal to decimal or vice versa with printf

From Brandonhutchinson.com

(Difference between revisions)
Jump to: navigation, search
(New page: * Hexadecimal to decimal: $ '''printf "%02X\n" ''decimal number''''' * Decimal to hexadecimal: $ '''printf "%d\n" hexadecimal number''''' == Examples == * Convert 1024 to hexadecimal....)
m
Line 3: Line 3:
* Decimal to hexadecimal:
* Decimal to hexadecimal:
-
$ '''printf "%d\n" hexadecimal number'''''
+
$ '''printf "%d\n" ''hexadecimal number'''''
== Examples ==
== Examples ==

Revision as of 22:16, 16 October 2007

  • 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