Commit 9592df80 authored by Nattapong Samanpong's avatar Nattapong Samanpong

ทำจสก pycharm ide เป็นครั้งแรก

parent 4a6a6f91
...@@ -139,6 +139,15 @@ ...@@ -139,6 +139,15 @@
"ยกตัวอย่างตัวเลขในเลขฐาน 2 เช่น 1, 101, 1101 เป็นต้น" "ยกตัวอย่างตัวเลขในเลขฐาน 2 เช่น 1, 101, 1101 เป็นต้น"
] ]
}, },
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
""
]
},
{ {
"cell_type": "markdown", "cell_type": "markdown",
"metadata": { "metadata": {
...@@ -233,7 +242,7 @@ ...@@ -233,7 +242,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 15, "execution_count": null,
"metadata": { "metadata": {
"slideshow": { "slideshow": {
"slide_type": "skip" "slide_type": "skip"
...@@ -336,6 +345,49 @@ ...@@ -336,6 +345,49 @@
"$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": null,
"metadata": {},
"outputs": [],
"source": [
"v = [0, 0, 0, 0, 1, 1, 0, 0]\n",
"sign = -1 if v[0] == 1 else 1\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",
"[(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)])\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"def value(v):\n",
" sign = -1 if v[0] == a else 1\n",
" return sign*sum([ v[i]*2**(4-i) for i in range(1,8)])"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"v = [1, 0, 0, 1, 0, 0, 1, 1]"
]
},
{ {
"cell_type": "markdown", "cell_type": "markdown",
"metadata": { "metadata": {
......
def value(v, pos=4, neg=3):
"""รับ v มาเพื่อหาค่าเป็นเลขฐานสิบ binary --> difital.
โดยค่ากำหนกเริ่มต้น
pos เป็น 4 หลัก
neg เป็น 3 หลัก
sign bit เป็นหลักแรกเสมอ
"""
sign = -1 if v[0] == 1 else 1
return sign*sum([v[i] * 2 ** (pos-i) for i in range(1, 1+pos+neg)])
def values(v, pos, neg):
sign = -1 if int(v[0]) == 1 else 1
return sign * sum([int(v[i]) * 2 ** (pos - i) for i in range(1, 1 + pos + neg)])
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment