-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbinaryConverter.java
More file actions
34 lines (33 loc) · 968 Bytes
/
binaryConverter.java
File metadata and controls
34 lines (33 loc) · 968 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
//simple Java program that takes a binary input from the user and allows them to
// choose the desired conversion to hexadecimal, octal, or decimal.
class deci_to_any
{
public static void main(String args[])
{
int n,b,i,j,k=1;
n=Integer.parseInt(args[0]);
b=Integer.parseInt(args[1]);
j=n;
while(j>=b)
{
k=k*b;
j=j/b;
}
while(k>0)
{
i=n/k;
switch(i)
{
case 10:System.out.print("A ");break;
case 11:System.out.print("B ");break;
case 12:System.out.print("C ");break;
case 13:System.out.print("D ");break;
case 14:System.out.print("E ");break;
case 15:System.out.print("F ");break;
default:System.out.print(i+" ");
}
n=n%k;
k=k/b;
}
}
}