-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
29 lines (28 loc) · 831 Bytes
/
Main.java
File metadata and controls
29 lines (28 loc) · 831 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
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
System.out.println("Enter a number:");
Scanner input = new Scanner(System.in);
int i = input.nextInt();
Word32 wrd = new Word32();
int n = 0;
int len = 31;
while(i > 0){
if(i % 2 != 0)
wrd.setBitN(len-n, new Bit(true));
n++;
i /= 2;
}
System.out.println("Binary val: " + wrd.toString());
int fin = 0;
int pow = 0;
for(int k = 31; k > 0; k--){
Bit b = new Bit(false);
wrd.getBitN(k, b);
if(b.getValue() == Bit.boolValues.TRUE)
fin += Math.pow(2, pow);
pow++;
}
System.out.println("Back to num: " + fin);
}
}