[Bash] Convert Octal to Decimal or Hex

Bash shell questions
Post Reply
User avatar
MigrationUser
Posts: 336
Joined: 2021-Jul-12, 1:37 pm
Contact:

[Bash] Convert Octal to Decimal or Hex

Post by MigrationUser »

02 Jan 2012 17:32
Hackjack


Hi guys. Ive started with bash some months ago and i wrote some useful Programs tongue

So here is what i need:

Code: Select all

printf "%x\n" DECIMALNUMBER Converts from decimal to hex
printf "%d\n" HEXNUMBER Converts from hex to Decimal

printf "%o\n" DECIMALNUMBER Converts from Decimal to OCTAL
printf "%o\n" HEXNUMBER Converts from Hex to OCTAL
My Question:

what is the command to convert FROM OCTAL to Decimal or Hex

Thank you

----------------------------

#2 02 Jan 2012 23:55
Simon Sheppard


Just prefix the number with 0 (Zero), that will indicate to bash that its an octal number.

I've added an example to the page:
https://ss64.com/osx/printf.html
https://ss64.com/bash/printf.html

----------------------------
#3 03 Jan 2012 16:13
Hackjack


awesome man! you are great
Post Reply