Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
N
numer-60-2
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Sivakorn Bupphadee
numer-60-2
Commits
127c6d90
Commit
127c6d90
authored
7 years ago
by
Sivakorn Bupphadee
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ส่งการบ้าน Week03 ฟังก์ชั่น value กับ values
parent
ce3bd11d
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
107 additions
and
1 deletion
+107
-1
Chapter 03 Numerics and Error Analysis.ipynb
week03/Chapter 03 Numerics and Error Analysis.ipynb
+79
-1
assignment.py
week03/assignment.py
+23
-0
test.py
week03/test.py
+5
-0
No files found.
week03/Chapter 03 Numerics and Error Analysis.ipynb
View file @
127c6d90
...
@@ -235,6 +235,7 @@
...
@@ -235,6 +235,7 @@
"cell_type": "code",
"cell_type": "code",
"execution_count": 15,
"execution_count": 15,
"metadata": {
"metadata": {
"collapsed": true,
"slideshow": {
"slideshow": {
"slide_type": "skip"
"slide_type": "skip"
}
}
...
@@ -289,6 +290,7 @@
...
@@ -289,6 +290,7 @@
"cell_type": "code",
"cell_type": "code",
"execution_count": 26,
"execution_count": 26,
"metadata": {
"metadata": {
"collapsed": true,
"slideshow": {
"slideshow": {
"slide_type": "skip"
"slide_type": "skip"
}
}
...
@@ -336,6 +338,82 @@
...
@@ -336,6 +338,82 @@
"$0.1 \\times 0.1 = 0.01 \\approx 0.0$ \n"
"$0.1 \\times 0.1 = 0.01 \\approx 0.0$ \n"
]
]
},
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"คำตอบ : 1.5\n"
]
},
{
"data": {
"text/plain": [
"1.5"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"#0 0000 000\n",
"#0 0011 000 => 3\n",
"#0 0001 100 => 1.5\n",
"v=[0,0,0,0,1,1,0,0]\n",
"sign = -1 if v[0] == 1 else 1 #if ง่ายๆ\n",
"value = v[1]*2**3\n",
"value += v[2]*2**2\n",
"value += v[3]*2**1\n",
"value += v[4]*2**0\n",
"\n",
"value += v[5]*2**-1\n",
"value += v[6]*2**-2\n",
"value += v[7]*2**-3\n",
"\n",
"print('คำตอบ :',sign*value)\n",
"\n",
"[ (i,4-i) for i in range(1,8)]\n",
"[ v[i]*2**(4-i) for i in range(1,8)]\n",
"sum([ v[i]*2**(4-i) for i in range(1,8)])"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"def value(v): #ออกสอบนาจ๊าาาาาาา เทียบ\n",
" sign = -1 if v[0] == 1 else 1 #if ง่ายๆ\n",
" return sign*sum([ v[i]*2**(4-i) for i in range(1,8)])"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"-2.375\n"
]
}
],
"source": [
"v = [1,0,0,1,0,0,1,1];\n",
"print(value(v))\n"
]
},
{
{
"cell_type": "markdown",
"cell_type": "markdown",
"metadata": {
"metadata": {
...
@@ -472,7 +550,7 @@
...
@@ -472,7 +550,7 @@
"name": "python",
"name": "python",
"nbconvert_exporter": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"pygments_lexer": "ipython3",
"version": "3.
5.2
"
"version": "3.
6.3
"
}
}
},
},
"nbformat": 4,
"nbformat": 4,
...
...
This diff is collapsed.
Click to expand it.
week03/assignment.py
0 → 100644
View file @
127c6d90
def
value
(
v
,
p
=
4
,
n
=
3
):
"""รับค่า v มาเพื่อหาค่าเป็นเลข binary -> digital.
โดยกำหนดค่าเริ่มต้น
p: เป็นจำนวนหลักที่ใช้เป้นจำนวนบวก 4 หลัก
n: เป็นจำนวนหลักที่ใช้เป็นจำนวนลบ 3 หลัก
sign bit : เป็นหลักแรกเสมอ
"""
sign
=
-
1
if
v
[
0
]
==
1
else
1
return
sign
*
sum
([
v
[
i
]
*
2
**
(
p
-
i
)
for
i
in
range
(
1
,
p
+
n
+
1
)])
def
values
(
v
,
p
=
4
,
n
=
3
):
a
=
[
int
(
i
)
for
i
in
v
]
sign
=
-
1
if
a
[
0
]
==
1
else
1
return
sign
*
sum
([
a
[
i
]
*
2
**
(
p
-
i
)
for
i
in
range
(
1
,
p
+
n
+
1
)])
#v = [0, 0,0,0,1,1,0,0]
#print(v)
#print(value(v))
#v = [1, 0,1,0,1, 0,1,1]
#print(v)
#print(value(v))
#print(values('10001100',p=4,n=3))
This diff is collapsed.
Click to expand it.
week03/test.py
0 → 100644
View file @
127c6d90
from
assignment
import
value
print
(
value
([
0
,
0
,
0
,
0
,
1
,
1
,
0
,
0
]))
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment