Hexadecimal to decimal or vice versa with printf
From Brandonhutchinson.com
(Difference between revisions)
(New page: * Hexadecimal to decimal: $ '''printf "%02X\n" ''decimal number''''' * Decimal to hexadecimal: $ '''printf "%d\n" hexadecimal number''''' == Examples == * Convert 1024 to hexadecimal....) |
|||
| (One intermediate revision not shown.) | |||
| Line 1: | Line 1: | ||
| - | * | + | * Decimal to hexadecimal: |
$ '''printf "%02X\n" ''decimal number''''' | $ '''printf "%02X\n" ''decimal number''''' | ||
| - | * | + | * 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
