-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfloating-points.html
194 lines (177 loc) · 13.7 KB
/
floating-points.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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title> Integer Conversion Encoding </title>
<meta name="viewport" content="width=device-width,height=device-height,initial-scale=0.9">
<meta name="description" content="An academic tool used to Convert and Encode Integers (of various bases).">
<meta name="author" content="Victoria Miteva, and others">
<meta name="keywords" content="convert, encode, integers, binary">
<link href="fpstyle.css" rel="stylesheet" type="text/css"/>
<!-- 7-segement display -->
<link href="https://fonts.cdnfonts.com/css/seven-segment" rel="stylesheet">
<!-- Google fonts-->
<link href="https://fonts.googleapis.com/css?family=Varela+Round" rel="stylesheet" />
<link href="https://fonts.googleapis.com/css?family=Nunito:200,200i,300,300i,400,400i,600,600i,700,700i,800,800i,900,900i" rel="stylesheet" />
<!-- CSS only -->
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-Zenh87qX5JnK2Jl0vWa8Ck2rdkQ2Bzep5IDxbcnCeuOxjzrPF/et3URy9Bv1WTRi" crossorigin="anonymous">
<!-- JavaScript Bundle with Popper -->
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-OERcA2EqjJCMA+/3y+gxIOqMEjwtxJY7qPCqsdltbNJuaOe923+mo//f6V8Qbsw3" crossorigin="anonymous"></script>
<!-- Three.js CDN -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/0.149.0/three.min.js" crossorigin="anonymous"></script>
<script>
window.addEventListener('DOMContentLoaded', event => {
// Navbar shrink function
var navbarShrink = function () {
const navbarCollapsible = document.body.querySelector('#mainNav');
if (!navbarCollapsible) {
return;
}
if (window.scrollY === 0) {
navbarCollapsible.classList.remove('navbar-shrink')
} else {
navbarCollapsible.classList.add('navbar-shrink')
}
};
// Shrink the navbar
navbarShrink();
// Shrink the navbar when page is scrolled
document.addEventListener('scroll', navbarShrink);
// Activate Bootstrap scrollspy on the main nav element
const mainNav = document.body.querySelector('#mainNav');
if (mainNav) {
new bootstrap.ScrollSpy(document.body, {
target: '#mainNav',
offset: 74,
});
};
// Collapse responsive navbar when toggler is visible
const navbarToggler = document.body.querySelector('.navbar-toggler');
const responsiveNavItems = [].slice.call(
document.querySelectorAll('#navbarResponsive .nav-link')
);
responsiveNavItems.map(function (responsiveNavItem) {
responsiveNavItem.addEventListener('click', () => {
if (window.getComputedStyle(navbarToggler).display !== 'none') {
navbarToggler.click();
}
});
});
});
</script>
</head>
<body class="bg-light" id="page-top">
<!-- Nav bar -->
<nav class="navbar navbar-expand-lg navbar-light fixed-top" id="mainNav">
<div class="container px-4 px-lg-5">
<a class="navbar-brand" href="index.html#page-top">Homepage</a>
<button class="navbar-toggler navbar-toggler-right" type="button" data-bs-toggle="collapse" data-bs-target="#navbarResponsive" aria-controls="navbarResponsive" aria-expanded="false" aria-label="Toggle navigation">
Conversion Menu
<i class="fas fa-bars"></i>
</button>
<div class="collapse navbar-collapse" id="navbarResponsive">
<ul class="navbar-nav ms-auto">
<li class="nav-item"><a class="nav-link" href="integer-conversion.html">Integer Conversion</a></li>
<li class="nav-item"><a class="nav-link" href="floating-points.html#float">Float Conversion</a></li>
<li class="nav-item"><a class="nav-link" href="conversion-sheets.html">More Resources</a></li>
</ul>
</div>
</div>
</nav>
<section>
<div class="container bg-light mt-5 pt-4">
<div class="text-center">
<h3 class="mb-4 text-underline"><b>Float Conversion</b></h3>
</div>
<form class="input" onsubmit="return false">
<div class="form-floating mb-3 mt-4 ml-auto gx-1">
<input type="text" id="inp" class="form-control bg-light" placeholder="16# - 0.00FACE" value="16# - 0.00FACE" oninput="floatConvert()">
<label for="floatingInputVal">Input a number</label>
</div>
</form>
<div class="row gap-5 mt-2 mb-5">
<div class="col-sm">
<div class="form-floating mb-3 mt-3 ml-auto gx-1 bg-light">
<input type="text" id="out16" class="form-control" placeholder="1 | 0 0110 | 1111 0101 10" value="1 | 0 0110 | 1111 0101 10" aria-label="Disabled input example" disabled readonly>
<label for="floatingInputVal">IEEE Binary-16</label>
</div>
<div class="mt-4">
<p class="step-wise mb-1"><strong>STEP-WISE PROCESS</strong></p>
</div>
<div class="container border-weight pt-2 px-2 lineheight rounded" id="border">
<div class="step-wise">
<p class="mb-0 bold">Step 1: Convert to Base 2</p>
<p class="mb-0">  2# <span id="base2">0000 . 0000 0000 1111 1010 1100 1110</span></p>
<p class="mb-0 bold">Step 2: Rewrite in Scientific Notation</p>
<p class="mb-0">  <span id="scien2">-1.1111 0101 1001 11 x 2^ - 1001 (-9) </span></p>
<p class="mb-0 bold">Step 3: Add bias to the exponent</p>
<p class="mb-0">  Binary16: Bias = 15</p>
<p class="mb-0">    <span id="exp">-9</span> + 15 = <span id="bias16">6</span></p>
<p class="mb-0 bold">Step 4: Convert new exponent value to binary</p>
<p class="mb-0">    <span id="bias16">6</span> = 2# <span id="biasBase2">0 0110</span></p>
<p class="mb-0 bold">Step 5: Check to see if the encoded exponent value fits into space available. If it doesn't fit, answer = "error"</p>
<p class="mb-0">  Binary16: Space = 5 bits</p>
<p class="mb-0">    <span id="biasBase2">0 0110</span> = <span id="bias16size"> 5 </span> bits, <span id="check16">FITS</span></p>
<p class="mb-0 bold">Step 6: Fill in the blanks</p>
<p class="mb-0">  Binary16: s | e eeee | mmmm mmmm mm *</p>
<!-- <p class="mb-0">    <u>SIGN:</u><span id="sign"> 0 </span> </p>
<P class="mb-0">      Shift left by 15 digits. (<< 15) </p>
<p class="mb-0">      Output: <span id="signOutput16">0 | x xxxx | xxxx xxxx xx</span></p>
<p class="mb-0">    <u>EXPONENT:</u> <span id="biasBase2">0 0110</span></p>
<p class="mb-0">      Shift left by 10 digits. (<< 10) </p>
<p class="mb-0">      Output: <span id="expOutput16">1 | 0 0110 | xxxx xxxx xx</span></p>
<p class="mb-0">    <u>MANTISSA:</u> <span id="mantissa16">1111 0101 10</span></p>
<p class="mb-0">      Shift right by 7 digits. (>> 7) </p>
<p class="mb-0">      Final Output: <span id="B16">1 | 0 0110 | 1111 0101 10</span></p> -->
<p class="mb-0">  <u>Answer:</u> <span id="B16">1 | 0 0110 | 1111 0101 10</span></p>
<p class="mb-0"><br>  *s = sign, e = exponent, m = mantissa</p>
<p class="mb-0">  <strong>Note</strong> that if the mantissa is too large to fit in the space available, precision is lost.</p>
</div>
</div>
</div>
<div class="col-sm">
<div class="form-floating mb-3 mt-3 ml-auto gx-1 bg-light">
<input type="text" id="out32" class="form-control" placeholder="1 | 0111 0110 | 1111 0101 1001 1100 0000 00" value="1 | 0111 0110 | 1111 0101 1001 1100 0000 00" aria-label="Disabled input example" disabled readonly>
<label for="floatingInputVal">IEEE Binary-32</label>
</div>
<div class="mt-4">
<p class="step-wise mb-1"><strong>STEP-WISE PROCESS</strong></p>
</div>
<div class="container border-weight pt-2 px-2 lineheight rounded">
<div class="step-wise">
<p class="mb-0 bold">Step 1: Convert to Base 2</p>
<p class="mb-0">  2# <span id="base2">0000 . 0000 0000 1111 1010 1100 1110</span></p>
<p class="mb-0 bold">Step 2: Rewrite in Scientific Notation</p>
<p class="mb-0">  <span id="scien2">-1.1111 0101 1001 11 x 2^ - 1001 (-9) </span></p>
<p class="mb-0 bold">Step 3: Add bias to the exponent</p>
<p class="mb-0">  Binary32: Bias = 127</p>
<p class="mb-0">    <span id="exp">-9</span> + 127 = <span id="bias32">118</span></p>
<p class="mb-0 bold">Step 4: Convert new exponent value to binary</p>
<p class="mb-0">    <span id="bias32">118</span> = 2# <span id="binaryBias32">0111 0110</span></p>
<p class="mb-0 bold">Step 5: Check to see if the encoded exponent value fits into space available. If it doesn't fit, answer = "error"</p>
<p class="mb-0">  Binary32: Space = 8 bits</p>
<p class="mb-0">    <span id="binaryBias32">0111 0110</span> = <span id="bias32size"> 8 </span> bits, <span id="check32">FITS</span></p>
<p class="mb-0 bold">Step 6: Fill in the blanks</p>
<p class="mb-0">  Binary32: s | eeee eeee | mmmm mmmm mmmm mmmm mmmm mmm *</p>
<!-- <p class="mb-0">    <u>SIGN:</u><span id="sign"> 1 </span> </p>
<P class="mb-0">      Shift left by 31 digits. (<< 31) </p>
<p class="mb-0">      Output: <span id="signOutput32">1 | xxxx xxxx | xxxx xxxx xxxx xxxx xxxx xxx</span></p>
<p class="mb-0">    <u>EXPONENT:</u> <span id="biasBase2">0111 0110</span></p>
<p class="mb-0">      Shift left by 23 digits. (<< 23) </p>
<p class="mb-0">      Output: <span id="expOutput32">1 | 0111 0110 | xxxx xxxx xx</span></p>
<p class="mb-0">    <u>MANTISSA:</u> <span id="mantissa32">1111 0101 1001 1100 0000 000</span></p>
<p class="mb-0">      Shift right by 9 digits. (>> 9) </p>
<p class="mb-0">      Final Output: <span id="B32">1 | 0111 0110 | 1111 0101 1001 1100 0000 000</span></p> -->
<p class="mb-0">  <u>Answer:</u> <span id="B32">1 | 0111 0110 | 1111 0101 1001 1100 0000 000</span></p>
<p class="mb-0"><br>  *s = sign, e = exponent, m = mantissa</p>
<p class="mb-0">  <strong>Note</strong> that if the mantissa is too large to fit in the space available, precision is lost.</p>
</div>
</div>
</div>
</div>
</div>
</section>
<script src="float.js"></script>
<footer class="footer bg-black small text-center text-white-50"><div class="container px-4 px-lg-5">Copyright © <img src="img/partyparrot.gif" alt="Party Parrot" style="margin-bottom: 15px;width:28px;height:28px"> 2022</div></footer>
</body>
</html>