| Author |
What java methods to use?
|
blackcarlos Dibia
Greenhorn
Joined: Mar 30, 2005
Posts: 21
|
|
pls what methods can be used to convert a number to binary then to an octet and finnally to a Hexdecimal I know of the toBinary() for the rest help
|
 |
Luciano Mantuaneli
Greenhorn
Joined: Dec 04, 2006
Posts: 13
|
|
If you don't bother in receive those convertions in a String format, you can use the Integer's methods: toBinaryString(int)toOctalString(int)toHexalString(int)However, if you declare an int variable and atribute a number prefixed with the zero digit, you assigning an actal value. The same happens for an hax value, if you prefix the number with "0x".
|
[]'s<br />Mantu<br /> <br />Sorry for my poor english...<br /> <br /><i>Time after time we lose sight of the way. Our causes cant see their effects</i> - Neil Peart
|
 |
blackcarlos Dibia
Greenhorn
Joined: Mar 30, 2005
Posts: 21
|
|
thanks a lot but I have already tried that may be I need to fully illustrate what I want I have a number say 236009 then convert to string then to octet and finally to hexidecimal output is this possible???
|
 |
Luciano Mantuaneli
Greenhorn
Joined: Dec 04, 2006
Posts: 13
|
|
I guess there is no such thing in Java...
|
 |
Jim Yingst
Wanderer
Sheriff
Joined: Jan 30, 2000
Posts: 18670
|
|
It really looks to me like this question has already been answered. For example: Gives output: Now if this isn't what you want...what sort of output are you expecting instead?
|
"I'm not back." - Bill Harding, Twister
|
 |
Divya Shastry
Greenhorn
Joined: Dec 05, 2006
Posts: 11
|
|
I think you require the following : Decimal I/P : Binary O/P - using toBinaryString(int i). You can also use toString(int i,2) Binary I/P : Octal O/P - as far a I know there's no method . So you can convert the binary input to Decimal value and then use toOctalString(int i) or toString(int i,8) Octal I/P : Hex O/P - similar to above .. Better suggestions are welcome !
|
 |
Sanjit Kumar
Ranch Hand
Joined: Dec 04, 2006
Posts: 35
|
|
hello black carlos......... my suggestion to you is to write your own methods for conevrting to binary and to octal rather that using any java method. This will help you to improve your programming skill.
|
 |
 |
|
|
subject: What java methods to use?
|
|
|