1import java.util.*;
2import java.util.Scanner;
3public class IntegerToBinary
4{
5 public static void main(String[] args)
6 {
7 int num;
8 String str = "";
9 Scanner sc = new Scanner(System.in);
10 System.out.println("Please enter the a number : ");
11 num = sc.nextInt();
12 // convert int to binary java
13 while(num > 0)
14 {
15 int y = num % 2;
16 str = y + str;
17 num = num / 2;
18 }
19 System.out.println("The binary conversion is : " + str);
20 sc.close();
21 }
22}
1public static String makeBinaryString(int n) {
2 StringBuilder sb = new StringBuilder();
3 while (n > 0) {
4 sb.append(n % 2);
5 n /= 2;
6 }
7 sb.reverse();
8 return sb.toString();
9}
1Integer.toString(100,8) // prints 144 --octal representation
2
3Integer.toString(100,2) // prints 1100100 --binary representation
4
5Integer.toString(100,16) //prints 64 --Hex representation