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
Phuengton Chummuel
numer-60-2
Commits
aa6d6eb9
Commit
aa6d6eb9
authored
Feb 01, 2018
by
Phuengton Chummuel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add week03 assignment
parent
ab2cc52a
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
29 additions
and
18 deletions
+29
-18
assignment.py
week03/assignment.py
+29
-18
No files found.
week03/assignment.py
View file @
aa6d6eb9
...
@@ -10,26 +10,37 @@ def value(v, p=4, n=3):
...
@@ -10,26 +10,37 @@ def value(v, p=4, n=3):
return
sign
*
sum
([
tmp
[
i
]
*
2
**
(
p
-
i
)
for
i
in
range
(
1
,
p
+
n
+
1
)])
return
sign
*
sum
([
tmp
[
i
]
*
2
**
(
p
-
i
)
for
i
in
range
(
1
,
p
+
n
+
1
)])
v
=
[
0
,
0
,
0
,
0
,
1
,
1
,
0
,
0
]
def
values
(
v
,
p
=
4
,
n
=
3
):
print
(
v
)
'''
print
(
value
(
v
))
รับค่า v มาเพื่อหาค่าเป็นเลขฐานสิบ
p เป็นจำนวนหลักที่ใช้เป็นบวก 4 หลัก
n เป็นจำนวนหลักที่ใช้เป็นลบ 3 หลัก
sign bit เป็นหลักแรกเสมอ
'''
tmp
=
[
int
(
i
)
for
i
in
v
]
sign
=
-
1
if
tmp
[
0
]
==
1
else
1
return
sign
*
sum
([
tmp
[
i
]
*
2
**
(
p
-
i
)
for
i
in
range
(
1
,
p
+
n
+
1
)])
# print(value([0, 0, 0, 0, 1, 0, 1, 1]))
v
=
[
1
,
0
,
1
,
0
,
1
,
0
,
1
,
1
]
# print(values('0000101000000', 5, 3))
print
(
v
)
# v = [0, 0, 0, 0, 1, 1, 0, 0]
print
(
value
(
v
))
# print(v)
# print(value(v))
v
=
[
1
,
0
,
0
,
0
,
0
,
0
,
1
,
1
,
0
,
0
,
0
,
0
]
# v = [1, 0, 1, 0, 1, 0, 1, 1
]
print
(
v
)
#
print(v)
print
(
value
(
v
,
6
,
5
))
# print(value(v
))
v
=
'100000110000'
# v = [1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0]
print
(
v
)
#
print(v)
print
(
value
(
v
,
6
,
5
))
#
print(value(v, 6, 5))
v
=
'000011
00'
# v = '1000001100
00'
print
(
v
)
#
print(v)
print
(
value
(
v
))
# print(value(v, 6, 5
))
v
=
'1000001010100
00'
# v = '100011
00'
print
(
v
)
#
print(v)
print
(
value
(
v
,
9
,
5
))
# print(value(v
))
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