Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Need to find what could be the potential problem in this

  1. #1
    Junior Member
    Join Date
    Apr 2012
    Posts
    1
    My Mood
    Daring
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Need to find what could be the potential problem in this

    I have written a code. A part of which will do a decimal to octal transformation.

    The function will take an Integer and convert it to corresponding octal number but return the result as String and not as number.

    class Foo {
    public static String dec_2_octal( int value) {
    StringBuilder ret = new StringBuilder();
    for(int i=0; i<31; i+=3) {
    ret.append((value & 7<<i) >> i);
    if( value <= (1<<(i+3))-1) break;
    }
    return ret.reverse().toString();
    }
    }

    Can any one point out what could the potential problem in this program???
    What I want to know, if this logic works??? or it may crash in some scenario??

    Thanks in advance.


  2. #2
    Member
    Join Date
    Jan 2012
    Location
    Hellas
    Posts
    284
    Thanks
    11
    Thanked 59 Times in 57 Posts

    Default Re: Need to find what could be the potential problem in this

    Quote Originally Posted by eternity007 View Post
    I have written a code. A part of which will do a decimal to octal transformation.
    The function will take an Integer and convert it to corresponding octal number but return the result as String and not as number.
    Can any one point out what could the potential problem in this program???
    What I want to know, if this logic works??? or it may crash in some scenario??

    Thanks in advance.
    Hello eternity007!
    You can use the Integer.toOctalString(int) method to accomplish your requirements , or at least test your code with it (btw I tested it and it seems to work properly).

Similar Threads

  1. can any one plz find the error.
    By shalini_sns in forum What's Wrong With My Code?
    Replies: 2
    Last Post: March 23rd, 2011, 05:26 PM
  2. Array List Help - Can't find where problem is!!
    By destructobob in forum What's Wrong With My Code?
    Replies: 5
    Last Post: February 22nd, 2011, 12:04 AM
  3. find LCS
    By Anemone_ in forum Algorithms & Recursion
    Replies: 1
    Last Post: November 28th, 2010, 02:03 PM
  4. Can't Find Problem
    By aussiemcgr in forum What's Wrong With My Code?
    Replies: 7
    Last Post: August 15th, 2010, 09:42 AM
  5. SIGAR to find CPU info-problem
    By ttsdinesh in forum Exceptions
    Replies: 7
    Last Post: October 4th, 2009, 10:33 AM