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).