Convert int to binary, hexadecimal and octal format
In this chapter you will learn:
Convert integer to binary, hexadecimal and octal format
An integer value can have hexadecimal and octal format other than decimal format. Integer class provides methods to convert an int value into various format.
static String toBinaryString(int i)
returns the binary string for i.static String toHexString(int i)
returns a hes string for i.static String toOctalString(int i)
returns a octal string for i.
public class Main {
public static void main(String[] args) {
// j a v a2 s. c o m
System.out.println(Integer.toBinaryString(10));
System.out.println(Integer.toHexString(10));
System.out.println(Integer.toOctalString(10));
}
}
The output:
Next chapter...
What you will learn in the next chapter:
Home » Java Tutorial » Primitive Data Types