-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNumberBaseConverter.java
More file actions
31 lines (24 loc) · 948 Bytes
/
NumberBaseConverter.java
File metadata and controls
31 lines (24 loc) · 948 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
import java.util.*;
public class NumberBaseConverter {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
boolean exit = false;
while (!exit)
{
String num = sc.next();
if (num.equals("-1"))
{
exit = true;
continue;
}
int binaryNumber = Integer.parseInt(num, 2);
// int num2 = (binaryNumber.length() + 7) & (-8);
// if (num2 != binaryNumber.length())
// {
// output = String.format("%0" + (num2 - binaryNumber.toString().length() ) + "d%s",0,binaryNumber.toString());
// }
System.out.println("The decimal representation of " + num + " is " + binaryNumber);
// System.out.println("The largest power of 2 that divides into " + num + " is " + result);
}
}
}