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

How to install Jaspersoft Studio on Eclipse

What is Advanced Encryption Standard (AEC) and online tool to encrypt and decrypt data using AEC.