Convert long value to binary, hex and octal format strings

ReturnMethodSummary
static StringtoBinaryString(long i)Returns a string representation in base 2.
static StringtoHexString(long i)Returns a string representation in base 16.
static StringtoOctalString(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
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.