-
Notifications
You must be signed in to change notification settings - Fork 2
/
float.html
122 lines (109 loc) · 2.99 KB
/
float.html
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Floating Point Binary Calculator</title>
<link rel="stylesheet" href="dist/app.css">
<link rel="stylesheet" href="dist/float.css">
<script src="dist/angular.js"></script>
<script src="dist/float.js"></script>
</head>
<body ng-app="app">
<h1>Floating Point Binary</h1>
<main ng-controller="FloatConverter">
<form class="input">
<p>
<label for="decimal">Decimal</label>
<input id="decimal" ng-model="decimal" type="number">
</p>
</form>
<section class="output">
<div class="sign" ng-if="bits.sign">
<p class="bits" ng-bind-html="sign | format_bits"></p>
<p class="desc">Sign</p>
</div>
<div class="exp" ng-if="bits.exp > 0">
<p class="bits" ng-bind-html="exp | format_bits"></p>
<p class="desc">Exponent</p>
</div>
<div class="mantissa">
<p class="bits" ng-bind-html="mantissa | format_bits"></p>
<p class="desc">Mantissa</p>
</div>
</section>
<form class="config">
<p>
<label for="sign_bit">Sign Bit</label>
<input id="sign_bit" ng-model="bits.sign" type="checkbox">
</p>
<p>
<label for="exp_length">Exponent Length</label>
<input type="number" ng-model="bits.exp" min="0" id="exp_length"> bits
</p>
<p>
<label>Exponent Format</label>
<label>
<input type="radio" ng-model="exp_format" value="twos">
Two's Complement
</label>
<label>
<input type="radio" ng-model="exp_format" value="signed">
Signed Magnitude
</label>
</p>
<p>
<label for="mantissa_length">Mantissa Length</label>
<input type="number" min="1" ng-model="bits.mantissa" id="mantissa_length"> bits
</p>
<p>
<label for="word_length">Word Length</label>
<input type="number" min="1" ng-model="word_len" ng-model-options="{getterSetter: true}" id="word_length"> bits
</p>
</form>
<div class="steps">
<section class="calculation">
<h3>Calculation</h3>
<p>{{ decimal }} × 2<sup>0</sup></p>
<p>{{ initial_mantissa }} × 2<sup>0</sup></p>
<p>0.{{ mantissa }} × 2<sup>{{ exp_decimal }}</sup></p>
<p>0.{{ mantissa }} × 2<sup>{{ exp }}</sup></p>
<p>{{ bits.sign ? sign : '' }} {{ exp }} {{ mantissa }}</p>
</section>
<section class="validation">
<h3>Validation</h3>
<table>
<tr>
<th>sign</th>
<td>{{ sign == '1' ? '-' : '+' }}</td>
</tr>
<tr>
<th>exponent</th>
<td>{{ exp }}<sub>2</sub></td>
</tr>
<tr>
<th></th>
<td>{{ exp_decimal }}<sub>10</sub></td>
</tr>
<tr>
<th>mantissa</th>
<td>0.{{ mantissa }}<sub>2</sub></td>
</tr>
<tr>
<th></th>
<td>{{ mantissa_decimal }}<sub>10</sub></td>
</tr>
<tr>
<th>decimal</th>
<td>{{ mantissa_decimal }} × 2<sup>{{ exp_decimal }}</sup></td>
</tr>
<tr>
<th></th>
<td>{{ converted_result }}</td>
</tr>
</table>
</section>
</div>
</main>
<p><a href="https://github.com/sheabunge/bintools">View source on GitHub</a></p>
</body>
</html>