1import java.util.Scanner;
2public class BinaryToHexadecimalJava
3{
4 public static void main(String[] args)
5 {
6 int[] hexaDecimal = new int[1000];
7 int a = 1, b = 0, r, decimal = 0, binary;
8 Scanner sc = new Scanner(System.in);
9 System.out.print("Please enter binary number: ");
10 binary = sc.nextInt();
11 while(binary > 0)
12 {
13 r = binary % 2;
14 decimal = decimal + r * a;
15 a = a * 2;
16 binary = binary / 10;
17 }
18 a = 0;
19 while(decimal != 0)
20 {
21 hexaDecimal[a] = decimal % 16;
22 decimal = decimal / 16;
23 a++;
24 }
25 System.out.print("Equivalent hexadecimal value is: ");
26 for(b = a - 1; b >= 0; b--)
27 {
28 if(hexaDecimal[b] > 9)
29 {
30 System.out.print((char)(hexaDecimal[b] + 55) + "\n");
31 }
32 else
33 {
34 System.out.print(hexaDecimal[b] + "\n");
35 }
36 }
37 sc.close();
38 }
39}