in this lecture I just wanted to cover 在本次讲座中，我只想介绍
some basic background in hexadecimal 一些十六进制
notation and ASCII representation this 表示法和 ASCII 表示的基本背景，这
is a kind of material that you've 是一种材料，
probably seen already if you're a 如果您是计算机科学专业的本科生，您可能已经看过了，
computer science undergraduate on the
other hand it's also the sort of 另一方面，它也是人们喜欢的
material that people sometimes assume 材料 有时
that their students know and so 假设他们的学生知道，因此
depending on the exact sequence of 根据
courses you've taken and the professor's 您所修课程的确切顺序以及
with whom you've taken them you may 与您一起学习的教授，您可能
never have seen this material explicitly 从未
presented in any class I also wanted to 在任何课程中明确介绍过这些材料 我也想
cover this material for those of you who 为那些人介绍这些材料 如果
aren't computer science majors so that 不是计算机科学专业的学生，那么
you'll be able to follow the following 您将能够听从下面的
lecture where we describe an 讲座，在那里我们描述
implementation of the one-time pad 了一次性填充方案的实现，
scheme so hexadecimal notation is just a 因此十六进制表示法只是
way of describing integers in a 一种描述不同基数的整数的方法，
different base other than the usual 而不是
decimal base that we're familiar with 我们熟悉的
hexadecimal notation uses base 16 which 十六进制表示法的常用十进制基数使用基数 16，这
means that as opposed to the standard 10 意味着与我们习惯的标准 10
digits that were used to we're going to 位数字相反，我们将
use a system in which there are 16 使用 在有 16
digits those digits are represented by 位数字的系统中，这些数字
the numbers 0 through 9 along with the 由数字 0 到 9 以及
six letters A through F and as indicated 六个字母 A 到 F 表示
in the table here each of those ，如表中所示，每个
hexadecimal digits corresponds to a 十六进制数字对应于
different value in the range of 0 to 15 0 到 15 范围内的不同值，
so the hex digits 0 through 9 comma 因此 十六进制数字 0 到 9 逗号
correspond to the values 0 through 9 and 对应于值 0 到 9，
then the hex digit a corresponds to 10 然后十六进制数字 a 对应于
the hex digit B corresponds to 11 and so 10 十六进制数字 B 对应于 11，依此
on up through the hex digit F which 类推，直到十六进制数字 F
corresponds to the value 15 hex digits 对应于值 15 十六进制数字
are also very convenient because there's 也非常 方便，因为
a one-to-one correspondence between each 每个
hex digit and sequences of 4 bits which 十六进制数字和 4 位序列之间
are sometimes also called a nibble 存在一对一的对应关系，有时也称为
right 4 bits is exactly half of a byte 半字节右侧 4 位正好是 8 位字节的一半，
which is 8 bits and so a sequence of 4
bits is sometimes also referred to as a 因此有时也称为 4 位序列 作为一个
nibble so as you see here again the hex 半字节，所以你在这里再次看到十六进制
digit 0 corresponds to the nibble 0 0 0 数字 0 对应于半字节 0 0 0
0 and so on up through the hex digit F 0 等等直到十六进制数字 F
which corresponds
the nibble one-one-one-one now these 对应于一个一对一的半字节 现在这些
correspondences aren't arbitrary what 对应关系不是任意的
you'll see is that each car each hex 你会看到每辆车
digit corresponding to a particular 对应于一个特定
nibble corresponds to the value of that 半字节的每个十六进制数字对应于该半字节的值，
nibble if you view it as a binary 如果你将它视为一个二进制
integer so just as an example if we look 整数，那么作为一个例子，如果我们查看
at the hex digit F right that
corresponds to the nibble 1 1 1 1 and in 对应于该半字节的十六进制数字 F right 1 1 1 1 并且在
binary notation the value 1 1 1 1 二进制符号中，值 1 1 1 1
corresponds to the number that we obtain 对应于我们获得的数字
or the value that we obtained by adding 或我们通过将
1 plus 2 plus 4 plus 8 right each 1 加 2 加 4 加 8
successive sequence in a binary number
has value twice the preceding one so 1 加起来而获得的值 所以 1
plus 2 plus 4 plus 8 is in fact equal to 加 2 加 4 加 8 实际上
the value 15 which is the value that 等于值 15，这是
corresponds to the hex digit out we can 对应于十六进制数字的值，我们
work through just a simple example to 可以通过一个简单的例子来
see how hex the values of hex numbers 了解如何计算十六进制数字
can be calculated so a value in hex is 的值 在十六进制
very often represented by prepending the 中通常通过在前缀 0 x2 前面加上值来表示，
prefix 0 x2 the value so if we try to 所以如果我们尝试
calculate the value of the hex number 10 计算十六进制数 10 的值，
well just as in the case in decimal 就像十进制的情况一样，
where each position is has value 10 其中每个位置的值都是前一个位置的 10 倍，每个位置
times the previous one and in binary 都是二进制的
each position has value twice the 位置值 tw ice
previous one in hexadecimal notation 十六进制表示法中的前一个
each position has value 16 times the 每个位置的值是前一个位置的 16 倍，
previous one so the hex number ten has 因此十六进制数 10 的
value equal to 16 times 1 plus 0 times 1 值等于 16 乘以 1 加 0 乘以 1
which in this case just reduces to 0 so ，在这种情况下，它只是减少到 0，因此
the value of the hex number 10 is equal 十六进制数 10 的值等于
to 16 represented in standard decimal 到以标准十进制
notation we can also represent that in 表示法表示的 16 我们也可以
terms of binary representation and it's 用二进制表示法来表示它
very easy to do that exactly because 很容易做到这一点正是因为
each hex digit corresponds to a nibble 每个十六进制数字对应一个半字节
so if we try to write out the binary 所以如果我们尝试写出
representation of the hex number 10 well 十六进制数 10 的二进制表示
we can just express that as the nibble 可以将其表示为
corresponding to 1 followed by the 对应于 1 的半字节，然后是
nibble corresponding to 0 and that's 对应于 0 的半字节，这
just 0 0 0 1 0 0 0 0 and again that 只是 0 0 0 1 0 0 0 0 并且再次
corresponds to the value 16 对应于值 16，
if we view that 8-bit number as a binary 如果我们在这里将 8 位数字视为二进制
number right here we have only a single 数 我们
one in the fifth position the fifth 在第五个位置只有一个，二进制数中的第五个位置的
position in a binary number has value 16 值为 16
and so the binary integer 0 0 0 1 0 0 0 ，因此二进制整数 0 0 0 1 0 0 0
0 is exactly equal to 16 and everything 0 正好等于 16，一切
works out nicely just as a second 都很好，就像我的第二个
example I have the hexadecimal number AF 例子 十六进制数 AF
AF is equal to or has value 16 times the AF 等于或具有值 16 乘以
value of a plus the value of F times 1 a 的值加上 F 乘以 1
the value of a is 10 the value of F is 的值 a 的值是 10 F 的值是
15 so we have 16 times 10 plus 15 times 15 所以我们有 16 乘以 10 加上 15 乘以
1 is equal to 175 and so the hex number 1 等于 175 所以十六进制数
AF is equal to the decimal number 175 AF 等于十进制数
and again if you write that out in 175 再次如果你用
binary then the hex number AF is equal 二进制写出那么十六进制数 AF
to the binary number 1 0 1 0 1 1 1 1 and 等于二进制数 1 0 1 0 1 1 1 1
you can check to yourself that viewed as 你可以检查自己被视为
a number in binary that is indeed equal 一个二进制数确实
to the decimal number 175 so nothing 等于十进制数 175 所以没有什么
very magical or mysterious there the 非常神奇或神秘的
next thing I want to talk about briefly 下一件我想简要谈谈的
is ASCII representation right ultimately 是 ASCII 表示 最终
everything in a computer is represented 计算机中的一切都表示
as bits and ASCII representation is very 为位，而 ASCII 表示
often used to represent English letter 经常用于
characters in ASCII representation each 以 ASCII 表示法表示英文字母字符 每个
character is represented using one byte 字符都使用一个字节
or 8 bits or equivalently two hex digits 或 8 位或等效的两个十六进制数字表示，
here we have a table indicating the 这里我们有一个表，指示
correspondences between characters in
the English alphabet along with other 英文字母表中的字符与其他
characters as well and their 字符之间的对应关系
corresponding ASCII equivalent you can 你也可以
find this table online I've just 在网上找到这个表
included it here for convenience you can ，为了方便起见，你可以
see that alongside every character the 看到，除了每个字符，
table includes both their ASCII 表中还包括了
representation written in hex as well as 用十六进制和十进制写的 ASCII 表示
in decimal again that's just for ，这只是为了
convenience and you can check that all 方便 并且您可以
the numbers line up by performed by 通过执行计算来检查所有数字是否排列，
performing a calculation just like we 就像我们
did a moment ago 刚才所做的
so just to go walk through an example if 那样，所以如果
we look at the character one right which 我们看一下字符 one right，它
is the the numeral one that has value 是具有值
hex 31 in the ASCII representation so hex 31 的数字字符，只需通过一个示例 在 ASCII 表示中，
that means that if you have a file say 这意味着如果您有一个文件，
and somewhere in that file you have the 并且在该文件中的某个地方，您有
character 1 that would actually be 字符 1，它实际上会
recorded in your computer as the hex 作为十六进制值 31 记录在您的计算机中，
value 31 or really what at the lower 或者实际上在较低
level it would be represented as a 级别它会被表示为
sequence of bits 0 0 1 1 0 0 0 1 right 位序列 0 0 1 1 0 0 0 1 right
so the nibble corresponding to 3 and the 所以对应于 3 的半字节和
nibble corresponding to 1 the key thing 对应于 1 的半字节
I'm pointing out here is that the 我在这里指出的关键是
character 1 is not the same thing as the 字符 1 不相同 将
number one right the character 1 is just 数字 1 视为正确的数字，字符 1 只是
a character and it's arbitrarily been 一个字符，它被任意
assigned the ASCII value the ASCII or 分配了 ASCII 值 ASCII 或
the value in the ASCII representation of
hex 31 and if you have a character 1 in 十六进制 31 的 ASCII 表示中的值，如果文件中有字符 1，
a file it's not stored as a single bit 1 则它不会存储为单个位 1
it's stored as the byte given by what's 它存储为由
displayed here 0 0 1 1 0 0 0 1 and 此处显示的内容给出的字节 0 0 1 1 0 0 0 1
similarly if we're representing the 类似地，如果我们表示
character capital F while the character 字符大写 F 而字符
capital F corresponds in the ASCII 大写 F 在 ASCII 表示中对应于
representation to the value hex 46 which
corresponds to the sequence of eight 对应于序列的值
bits 0 1 0 0 0 1 1 0 and so the 八位 0 1 0 0 0 1 1 0 所以
character F in a file would ultimately 文件中的字符 F 最终
be represented in your computer as the 将在您的计算机中表示为
sequence of 8 bits described here now 这里描述的 8 位序列 现在
one point I want to make and this is a 我想提出一点，这
bit of an advanced point and if you 是一个高级观点 如果你
don't understand it I wouldn't really 不理解它，我不会真的很
worry about it 担心它
very much but this is going to come into ，但是
play when we show the implementation of 当我们
the one-time pad in the next lecture the 在下一课中展示一次性垫的实现时，这将发挥作用，
question is how did we store the value 问题是我们如何存储价值
hex 1f for example to a file and there 十六进制 1f 例如 一个文件，
are two natural ways we could go about 我们可以用两种自然的方式
doing this the first possibility is what 来做这件事，第一种可能性是
I'll call native hex so will store the 我称之为本机十六进制，因此将存储
value exactly as the sequence of bits 值完全作为它代表的位序列，
that it represents so we've seen already 所以我们已经
that the hex value 1f corresponds to the 看到十六进制值 1f 对应于
sequence of 8 bits 0 0 0 1 1 1 1 1 so 8 位 0 0 0 1 1 1 1 1 的序列，所以
what we could do is just store the value 我们可以做的只是将值
hex 1f to a file as hex 1f 存储到一个文件中，
of eight bits 0 0 0 1 1 1 1 1 now that's 作为 8 位 0 0 0 1 1 1 1 1 现在这
all well and good the problem with that 一切都很好问题
is that if we then try to view that file 也就是说，如果我们然后尝试
using a standard text editor we'll get a 使用标准文本编辑器查看该文件，我们将得到一个
none printable character and if you go 不可打印的字符，如果您
back and look at the ASCII table you'll 返回并查看 ASCII 表，您将
see that the hex value 1f corresponds to 看到十六进制值 1f 对应于
some unprintable character not a regular 某些不可打印的字符 不是
character in the alphabet or a numeral 字母表中的常规字符，也不是数字
or punctuation or anything like that 或标点符号或类似的东西，
that's okay if all you're doing is 如果您所做的只是
reading to that file from a program but 从程序中读取该文件，那没关系，但是
it's inconvenient if we're trying to 如果我们试图
look at the file or manipulate the file 查看文件或操作文件
by hand a second possibility is to store ，则很不方便 第二种可能性是
the hex value 1 f as the ASCII 将十六进制值 1 f 存储为 AS CII
characters 1f if we do that then recall 字符 1f 如果我们这样做，那么回想
that every ASCII character is 一下每个 ASCII 字符都
represented using one byte so what we 使用一个字节表示，所以我们
now have is something stored using 2 现在拥有的是使用 2 个字节存储的东西，
bytes rather than one that is using 16 而不是使用 16
bits rather than 8 right if we store the 位而不是 8 位存储的东西，如果我们将
ASCII characters 1f to a file then what ASCII 字符 1f 存储到一个 文件然后
we'll end up actually storing in terms 我们最终实际存储
of bits is 0 0 1 1 0 0 0 1 0 1 0 0 0 1 1 的位是 0 0 1 1 0 0 0 1 0 1 0 0 0 1 1
0 right which I you obtained just by 0 正确的我只是通过
looking up the character one in the 在 ASCII 文件中查找字符 1 获得
ASCII file the character F in the ASCII 的字符 F
file and writing out their corresponding
representations now if we view this file 如果我们
using a text editor or from the command 使用文本编辑器或
line we see what we expect we see the 从命令行查看该文件，我们会看到我们期望的内容
characters 1f if we read it from a 如果我们从程序中读取它，我们会看到字符 1f
program then what the program is going 那么程序
to see is that sequence of 16 bits and 将看到什么 是那个 16 位的序列，
so we just need to be careful to tell 所以我们只需要小心地
the program to convert that sequence of 告诉程序将该
16 bits into the hex value 1 m for many 16 位的序列转换为十六进制值 1 m 对于许多
programs there's a standard way provided 程序有一个标准的方法
to do that it's also not extremely 来做到这一点也不是
difficult to do that on your own or to 很难做到 自己或
build a small macro to do it on your own 建立 一个可以自己完成的小宏，
you just have to be careful to keep 您只需要注意
track of how you're representing your 跟踪您如何
hex values in the file 在文件中表示十六进制值，
we'll see this come into play in a 我们将
little bit more detail in the following 在接下来的讲座中更详细地看到这一点
lecture