You are not logged in.

#1 02 Jan 2012 17:32

Hackjack
Member
Registered: 02 Jan 2012
Posts: 3

[Bash] Convert Octal to Decimal or Hex

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

So here is what i need:

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

Offline

#2 02 Jan 2012 23:55

Simon Sheppard
Admin
Registered: 27 Aug 2005
Posts: 1,130
Website

Re: [Bash] Convert Octal to Decimal or Hex

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:
http://ss64.com/osx/printf.html
http://ss64.com/bash/printf.html

Offline

#3 03 Jan 2012 16:13

Hackjack
Member
Registered: 02 Jan 2012
Posts: 3

Re: [Bash] Convert Octal to Decimal or Hex

awesome man! you are great

Offline

#4 03 Jan 2012 16:27

Hackjack
Member
Registered: 02 Jan 2012
Posts: 3

Re: [Bash] Convert Octal to Decimal or Hex

sorry for double posting.

can i ask here another Question or should i open a new thread?


my question is:

i compare to files (FILE1 & FILE2) in therr are numbers

File 1: 19,18
File 2: 19,17

i use the command: cmp --verbose $FILE1 $FILE2 >>aim

in the aim file it says line 1(offset) and the number thats different 17

my question:

how can i read the number 17 out if the file? not the number one? only the number 17?
because i want to convert this number.

ok i know that its 17 but i want:

binarycompare
copy the results out of a File
convert the results

(Important for that is that i dont know the number of the results..

something like:

getnumber of=aim then printf "%d\n" 0+number in aimfile

any ideas?

do you understand me?

Offline

Board footer

Powered by