Convert long value to binary, hex and octal format strings
static String toBinaryString(long i)
- Returns a string representation in base 2.
static String toHexString(long i)
- Returns a string representation in base 16.
static String toOctalString(long i)
- Returns a string representation in base 8.
It is simple to convert long value to its binary, hexdecimal and octal forms:
public class Main {
public static void main(String[] args) {
System.out.println(Long.toBinaryString(10));
System.out.println(Long.toHexString(15));
System.out.println(Long.toOctalString(10));
}
}
The output:
1010
f
12
Home
Java Book
Essential Classes
Java Book
Essential Classes
Long:
- Long class
- Constants value from Long class
- Constructors from Long
- Convert long value to byte, double, float, int, long, short
- Decode a string to create long value
- Get the long value from a system property
- Compare two long values
- Parse long value from string
- Convert long value to binary, hex and octal format strings
- Convert long value to string
- Get the sign of the long value
- Get the number of zero bits preceding and following
- Reverse and rotate a long value