-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdec2bin.java
More file actions
85 lines (73 loc) · 1.91 KB
/
dec2bin.java
File metadata and controls
85 lines (73 loc) · 1.91 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
class dec2bin {
static MIPS_OS_Interface mips = new MIPS_OS_Interface();
static void dec2bin(int number) {
int count = 0;
int d = 3;
int n = number;
int rem = 0;
ydob: for(; n != 0 ;){
rem = n%2;
n = n/2;
mips.push(rem);
count = count + 1;
continue ydob;
}
enod: ;
loop: for ( ; count > 0;) {
d = mips.pop();
count = count - 1;
mips.print_d(d);
continue loop;
}
done: ;
}
static void fractional2bin(int fractional,
int precision,
int max_size) {
int max = 0;
int n = fractional;
int count = 0;
int tmp;
//The Math.pow()
max = 1;
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;
}
}