Java Integer toOctalString() Method
Example
Write numbers in octal:
public class Main {
public static void main(String[] args) {
System.out.println(Integer.toOctalString(8));
System.out.println(Integer.toOctalString(64));
System.out.println(Integer.toOctalString(255));
}
}
Definition and Usage
The toOctalString() method returns a string with the number written in octal (base 8, with only the digits 0 to 7).
For a negative number, the result is long, because it shows how Java stores the number. For example, -1 gives 37777777777.
Tip: Use toBinaryString() for binary and toHexString() for hexadecimal.
Syntax
public static String toOctalString(int i)
Parameter Values
| Parameter | Description |
|---|---|
| i | Required. The number to convert. |
Technical Details
| Returns: | A String with the number in octal. |
|---|
Related Pages
❮ Integer Methods