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

Best Website List For Java Programming Exercises, Practice, Solution

Steps To Create Java Web Application With Tomcat Server With AWS Elastic Beanstalk