You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

103 lines
2.9 KiB

{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 数值数据的编码 \n",
"__数值数据是一类常见数据,是可用于算术运算的具体数\n",
"值。例如,鸟的数量是 21 只,这个数值数据在计算机中是如 何表示的呢?\n",
"计算机中的数值数据是以补码的方式表示的,以十进制 数 +21 和 -21 的 8 位编码为例,它们的二进制数、原码、反 码和补码分别如下。__"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"$(+21)_{10}=(+10101)_2$ $(-21)_{10}=(-10101)_2$\n",
"\n",
" $[+10101]_{原}= 00010101 $ \n",
" \n",
" $[+10101] 反= 00010101 $\n",
" \n",
" $[+10101] _{补}= 00010101$\n",
" \n",
"$[-10101]_{原}= 10010101 $\n",
"\n",
"$[-10101]_{反}= 11101010 $\n",
"\n",
"$[-10101]_{补}= 11101011$"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 文本数据的编码\n",
"__记录鸟类活动时需要记录鸟的名称,例如灰眶雀鹛的学\n",
"名是 Alcippe Morrisonia。对这些由字母构成的数据,计算机 是如何存储和表示的呢?\n",
"字母、数字、标点符号等,称为西文字符。计算机在存储 和处理这些西文字符时,需要为每个字符规定一个由 0 和 1 组成的代码。目前,国际上普遍采用的西文字符编码标准是 ASCII 码(American Standard Code for Information Interchange, 美国标准信息交换代码)。__"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"__下面的代码块完成了字符与ASCII码之间的编码转化,块运行代码,动手验证一下吧!__"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"请输入一个字符: 4\n",
"请输入一个ASCII码: 5\n",
"4 的ASCII 码为 52\n",
"5 对应的字符为 \u0005\n"
]
}
],
"source": [
"c = input(\"请输入一个字符: \")\n",
" \n",
"# 用户输入ASCII码,并将输入的数字转为整型\n",
"a = int(input(\"请输入一个ASCII码: \")) \n",
"print( c + \" 的ASCII 码为\", ord(c))\n",
"print( a , \" 对应的字符为\", chr(a))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.3"
}
},
"nbformat": 4,
"nbformat_minor": 2
}