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
Post a Comment