• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

What java methods to use?

 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
      Number of slices to send:
      Optional 'thank-you' note:
    • 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
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    I guess there is no such thing in Java...
     
    Wanderer
    Posts: 18671
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • 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?
     
    Greenhorn
    Posts: 11
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • 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 !
     
    Ranch Hand
    Posts: 35
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • 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.
     
    reply
      Bookmark Topic Watch Topic
    • New Topic