-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathch3_2com.html
More file actions
108 lines (101 loc) · 3.84 KB
/
ch3_2com.html
File metadata and controls
108 lines (101 loc) · 3.84 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
<!DOCTYPE html>
<html>
<head>
<title>CS319 Practices - Two's Complement Representation</title>
<META http-equiv="Content-Type" content="text/html; charset=UTF-8">
<META name="description" content="Practice Tools for Internal Data Representation Concepts in Computer Architecture Course">
<META name="keywords" content="Two's Complement, 2's complement, signed integer representation, data representation, practice tool, Computer Architecture, Computer Organization">
<META http-equiv="Cache-Control" content="no-cache">
<link rel="stylesheet" href="assets/css/stylesp.css">
</head>
<body>
<ul class="breadcrumb">
<li><a href=".">Home</a></li>
<li>Two's Complement Representation</li>
</ul>
<h2>Two's Complement Representation</h2>
<p>This section includes exercises on converting between 2's complement and decimal. </p>
<p>How to use an exercise:</p>
<ul>
<li>Follow steps 1-2-3-4, but you may use the "Start" button of an exercise at any time to restart.</li>
<li>Looking for examples of how to solve a problem? Just click "Start" in step 1, type something for step 2, and move to the step-by-step solution in step 4.</li>
</ul>
<h4>Exercise 1. Convert 8-bit 2's Complement to Decimal</h4>
<p>Reference: <a href="https://youtu.be/yBz7_l1MFj0?t=410" alt="lecture on converting a 2's complement number to decimal" target="_blank">lecture on converting a 2's complement number to decimal</a>.</p>
<table>
<tr>
<td>1. Generate a random 8-bit 2's Complement number: </td>
<td><button id="p1StartBtn" type="button" onclick="p1RandomN()">Start</button></td>
<td><p id="p1Data"></p></td>
</tr>
<tr>
<td>2. Please convert it to decimal:</td>
<td>-</td>
<td><input id="p1Input"></td>
</tr>
<tr>
<td>3. Now check your answer:</td>
<td><button id="p1CheckBtn" type="button" onclick="p1CheckResult()" disabled="true">Check</button></td>
<td><p id="p1Result">-</p></td>
</tr>
<tr>
<td>4. Show the solution:</td>
<td><button id="p1AnswerBtn" type="button" onclick="p1ShowAnswer()" disabled="true">Solution</button></td>
<td><p id="p1Answer">-</p></td>
</tr>
<tr>
</table>
<h4>Exercise 2. Convert Decimal to 8-bit 2's Complement</h4>
<p>Reference: <a href="https://youtu.be/wmjx7GhVvTo" alt="lecture on converting a decimal to 2's complement format" target="_blank">lecture on converting a decimal to 2's complement format</a>.</p>
<table>
<tr>
<td>1. Generate a random decimal number: </td>
<td><button id="p2StartBtn" type="button" onclick="p2RandomN()">Start</button></td>
<td><p id="p2Data"></p></td>
</tr>
<tr>
<td>2. Please convert it to 8-bit 2's Complement:</td>
<td>-</td>
<td><input id="p2Input"></td>
</tr>
<tr>
<td>3. Now check your answer:</td>
<td><button id="p2CheckBtn" type="button" onclick="p2CheckResult()" disabled="true">Check</button></td>
<td><p id="p2Result">-</p></td>
</tr>
<tr>
<td>4. Show the solution:</td>
<td><button id="p2AnswerBtn" type="button" onclick="p2ShowAnswer()" disabled="true">Solution</button></td>
<td><p id="p2Answer">-</p></td>
</tr>
<tr>
</table>
<script src = "js/ch3work_2com.js"></script>
<h2> </h2>
<p>
<b>© 2022
Bin Peng</b><br>
Bug reports and comments are welcome: crystal dot peng at park dot edu<br><br>
Last Update:
<script type="text/javascript">
var month=new Array(12);
month[0]="January";
month[1]="February";
month[2]="March";
month[3]="April";
month[4]="May";
month[5]="June";
month[6]="July";
month[7]="August";
month[8]="September";
month[9]="October";
month[10]="November";
month[11]="December";
moddate=new Date(document.lastModified); //convert to local time
document.write(month[moddate.getMonth()]+" "+ moddate.getDate()+", "+ moddate.getFullYear());
</script>
<br>
Created: November 17, 2018
</p>
</body>
</html>