• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

What java methods to use?

 
blackcarlos Dibia
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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".

     
    blackcarlos Dibia
    Greenhorn
    Posts: 21
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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
    Posts: 13
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    I guess there is no such thing in Java...
     
    Jim Yingst
    Wanderer
    Sheriff
    Posts: 18671
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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?
     
    Divya Shastry
    Greenhorn
    Posts: 11
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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
    Posts: 35
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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.
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic