This week's book giveaway is in the Android forum.We're giving away four copies of Head First Android and have Dawn & David Griffiths on-line!See this thread for details.
Big Moose Saloon
 Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies Register / Login Win a copy of Head First Android this week in the Android forum!

Conversion

rubna
Greenhorn

Joined: Jun 15, 2000
Posts: 25
Hi,
Thanks
rubna
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
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

Carl Trusiak
Sheriff

Joined: Jun 13, 2000
Posts: 3340
Originally posted by rubna:
Hi,
Thanks
rubna

You can use the methods in the Integer Wrapper class

I Hope This Helps
Carl Trusiak, SCJP2, SCWCD
rubna
Greenhorn

Joined: Jun 15, 2000
Posts: 25
Originally posted by Carl Trusiak:
[B]
[/B]

Thsnks a lot Carl.
rubna
Greenhorn

Joined: Jun 15, 2000
Posts: 25
Originally posted by Nirmal:
Hi Rubna,
For Decimal to Octal:

Thanks a lot.

subject: Conversion