File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Conversion Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Conversion" Watch "Conversion" New topic
Author

Conversion

rubna
Greenhorn

Joined: Jun 15, 2000
Posts: 25
Hi,
Does anyone know how to convert Hexadecimal to Decimal & octal to decimal?If so,please help me.
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,
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

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Conversion
 
Similar Threads
getting numberformatexception For input string: "500.0"
Invocation init()
Decimals not converting to correct fractions
Questions about switch ... case ?
fundamentals