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.
Code :
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.
Re: Need to find what could be the potential problem in this
Quote:
Originally Posted by
eternity007
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).