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....)
Current revision (17:02, 9 January 2008) (edit) (undo)
 
(One intermediate revision not shown.)
Line 1: Line 1:
-
* Hexadecimal to decimal:
+
* Decimal to hexadecimal:
$ '''printf "%02X\n" ''decimal number'''''
$ '''printf "%02X\n" ''decimal number'''''
-
* Decimal to hexadecimal:
+
* Hexadecimal to decimal:
-
$ '''printf "%d\n" hexadecimal number'''''
+
$ '''printf "%d\n" ''hexadecimal number'''''
== Examples ==
== Examples ==

Current revision

  • Decimal to hexadecimal:
$ printf "%02X\n" decimal number
  • Hexadecimal to decimal:
$ 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