rubna

Greenhorn

Posts: 25

Anonymous

Ranch Hand

Posts: 18944

posted 17 years ago

Hi Rubna,

For Decimal to Octal:

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

Hope you know that ,for Octal the base value is "8" and allowed digits are 0,1,2,3,4,5,6,7.

For example let us take decimal value 138

Divide this number by the Octal base value and quotient becomes not divisible by base value.

so 138/8 ie the remainder is 2 and Quotient is 17.

Then divide the quotient by 8 ie(17/8) the remainder is 1 and quotient is 2 and this can not be divided

again and so write the answers only including last quotient to the first remainder.

For example in this case 0212 is the Octal value for Decimal 138.

For Octal to Decimal:

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

Powers of 8 will come into picture.

For example in this the Octal Number is 0212.

2 X 8^0 +1 X 8^1 + 2 X 8 ^ 2 ,the MSB ,here is the Octal indication digit. and it will not have any impact on

the conversion.

The result is 2 + 8 + 128 = 138.

Hope this can help you and for better understanding you have to work out by yourself.

For Hexam decimal use Base 16 and digits are 0 to 9,a,b,c,d,e,f(ie 0 to 15).

For Hexa decimal representation prefix is 0X(Zero X).

The conversion process is the same and so you can try on that.

Hope it helps you.

Thanks

Nirmal

For Decimal to Octal:

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

Hope you know that ,for Octal the base value is "8" and allowed digits are 0,1,2,3,4,5,6,7.

For example let us take decimal value 138

Divide this number by the Octal base value and quotient becomes not divisible by base value.

so 138/8 ie the remainder is 2 and Quotient is 17.

Then divide the quotient by 8 ie(17/8) the remainder is 1 and quotient is 2 and this can not be divided

again and so write the answers only including last quotient to the first remainder.

For example in this case 0212 is the Octal value for Decimal 138.

For Octal to Decimal:

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

Powers of 8 will come into picture.

For example in this the Octal Number is 0212.

2 X 8^0 +1 X 8^1 + 2 X 8 ^ 2 ,the MSB ,here is the Octal indication digit. and it will not have any impact on

the conversion.

The result is 2 + 8 + 128 = 138.

Hope this can help you and for better understanding you have to work out by yourself.

For Hexam decimal use Base 16 and digits are 0 to 9,a,b,c,d,e,f(ie 0 to 15).

For Hexa decimal representation prefix is 0X(Zero X).

The conversion process is the same and so you can try on that.

Hope it helps you.

Thanks

Nirmal

Carl Trusiak

Sheriff

Posts: 3341

posted 17 years ago

You can use the methods in the Integer Wrapper class

Originally posted by rubna:

Hi,

Does anyone know how to convert Hexadecimal to Decimal & octal to decimal?If so,please help me.

Thanks

rubna

You can use the methods in the Integer Wrapper class

I Hope This Helps

Carl Trusiak, SCJP2, SCWCD

rubna

Greenhorn

Posts: 25