Page 555 - Cs_withBlue_J_C11_Flipbook
P. 555
56 case 12: hexVal += "C"; break;
57 case 11: hexVal += "B"; break;
58 case 10: hexVal += "A"; break;
59 default: hexVal += Integer.toString(dig);
60 }
61 num = num / 16;
62 }
63 System.out.print("Hexadecimal Value of " + num1 + " : " );
64 for (counter = hexVal.length() - 1; counter >= 0; counter--)
65 System.out.print(hexVal.charAt(counter));
66 }
67
68 void deci_other()
69 {
70 int ch,t,num;
71 Scanner sc = new Scanner(System.in);
72 System.out.println("Enter number to convert : ");
73 num=sc.nextInt();
74 System.out.println("Enter 1 for Binary");
75 System.out.println("Enter 2 for Octal");
76 System.out.println("Enter 3 for Hexadecimal");
77 System.out.println("Enter 4 for Exit");
78 ch=sc.nextInt();
79 switch(ch)
80 {
81 case 1 : dec2bin(num); break;
82 case 2 : dec2oct(num); break;
83 case 3 : dec2hex(num); break;
84 default: System.out.println("Wrong Choice");
85 }
86 System.out.println("\n--------------------------------");
87 }
88
89 void bintodeci(int bin)
553
Sample Projects 553

