Convert from Decimal to Binary, Octal or Hex in Java using Integer.toXXXString(int)

Integer class does provide lots of unitily methods to be consumed directly

Integer decimal1 = 21;
System.out.println(decimal1 + "=" + Integer.toBinaryString(decimal1));
Integer decimal2 = 302;
System.out.println(decimal2 + "=" + Integer.toOctalString(decimal2));
Integer decimal3 = 43981;
System.out.println(decimal3 + "=" + Integer.toHexString(decimal3));
Output:
21 = 10101
302 = 456
43981 = abcd

Comments

Popular posts from this blog

How to Install AnyDesk remote desktop client on Ubuntu

Top 5 Websites for Java Application Examples with source code

How to create exe of java application using launch4j and inno setup compiler