-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfractional2bin.java
More file actions
60 lines (52 loc) · 1.59 KB
/
fractional2bin.java
File metadata and controls
60 lines (52 loc) · 1.59 KB
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
class fractional2bin {
static MIPS_OS_Interface mips = new MIPS_OS_Interface();
static void fractional2bin(int fractional,
int precision,
int max_size) {
int max = 0;
int n = fractional;
int count = 0;
int tmp;
//the java code for the pow() macro // max = (int)Math.pow(10, precision);
max = 1; //result = max //tmp = precison //base = 10
tmp = precision;
loop3: for(; tmp != 0 ;) {
max = max * 10;
tmp = tmp - 1;
continue loop3;
}
done3: ;
bb: for(count=0; count < max_size; ) {
n = n * 2;
if (n == 0) break; //break to se
if ( n >= max ) {
cons: ;
mips.print_di(1);
n = n - max;
//break fi;
} else {
alt: ;
mips.print_di(0);
//break fi;
}
fi: ;
count = count +1;
continue bb;
}
se: ;
return;
}
public static void main(String[] args){
final int mantissa_size = 23;
// This is the number of bits in a binary32 mantissa
int arg_0 = Integer.parseInt(args[0]);
char arg_1 = args[1].charAt(0);
int arg_2 = Integer.parseInt(args[2]);
int precision = args[2].length();
// dec2bin(arg_0);
// mips.print_c(arg_1);
fractional2bin(arg_2, precision, mantissa_size);
mips.print_c('\n');
return;
}
}