关于计算机中数字表示的几个问题?

发布于 2024-08-16 17:38:21 字数 892 浏览 2 评论 0原文

我从以下书籍开始学习汇编语言:80x86 汇编语言和计算机体系结构简介

这来自在计算机中表示数据

我们研究了两种方案 代表数字-

  1. 通过使用二进制整数(通常以十六进制表示)或
  2. 使用 ASCII 代码。

但是,这些方法有两个 问题:

我不明白这些问题。

1:可用于表示数字的位数是有限的,并且

我没有得到这一点。他在说什么?

2:不清楚如何表示负数。

美好的

求解第一个表示 上面提到的问题,你可以 只需包含减号的代码 符号。例如,ASCII 码 对于四个字符 -817 是 2D (负数)、38、31 和 37。

我认为这是第二个表示问题。但好吧,我明白了。

要解决第一个问题,你可以 始终同意使用固定数量的 字节,可能在左侧填充 用 ASCII 代码表示零或空格。

我不知道他想说什么。 零或空格的 ASCII 代码。??

或者,您可以使用 字节数可变,但同意 该数字以最后一个结尾 数字的 ASCII 码,即 用 a 终止字符串 非数字。

我一个字也没听懂。

我不知道为什么。但我无法理解他想说什么。任何人都可以解释一下这一点。 (例子会很棒)

I started learning Assembly language from the book: Introduction to 80x86 Assembly Language and Computer Architecture

This is from the Representing Data in a Computer

We have looked at two schemes to
represent numbers-

  1. by using binary integers (often expressed in hex) or
  2. by using ASCII codes.

However, these methods have two
problems:

I didn't understand these problems.

1: the number of bits available for representing a number is limited, and

I didn't get this. What is he saying?

2: it is not clear how to represent a negative number.

fine

To solve the first representation
problem mentioned above, you can
simply include the code for a minus
sign. For example, the ASCII codes
for the four characters -817 are 2D
(for minus), 38, 31, and 37.

I think its second representation problem. But ok, I got it.

To solve the first problem, you could
always agree to use a fixed number of
bytes, perhaps padding on the left
with ASCII codes for zeros or spaces.

I've no clue about what he wants to say. ASCII codes for zeros or spaces.??

Alternatively, you could use a
variable number of bytes, but agree
that the number ends with the last
ASCII code for a digit, that is,
terminating the string with a
nondigit.

I didn't get a single word.

I don't know why. But I cannot understand what he is trying to say. Could any one explain this. (examples would be great)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

假扮的天使 2024-08-23 17:38:21

哇。我还没有读过这本书,但如果你的摘录是准确的,我不会后悔我错过了它。

数字的二进制表示受到用于表示数字的位数的限制。不过,您可以定义使用大量或可变位数的表示形式。您可以在左侧填充二进制零(或负数的二进制补码表示形式)。

数字的 ASCII 表示可以按照书中的描述来完成。 ASCII 的问题在于操作数字比较困难:加法相当简单,但想象一下除法会是什么样子。

Wow. I haven't read the book, but if your excerpts are accurate, I'm not sorry that I missed it.

Binary representation of numbers is limited by the number of bits used to represent the number. You could define a representation that uses an large or variable number of bits, though. You'd pad on the left with binary zeros (or ones in a two's complement representation of a negative number).

ASCII representation of numbers could be done as the book describes. The problem with ASCII is that manipulating the numbers is harder: Addition is fairly simple, but imagine what division would look like.

一袭白衣梦中忆 2024-08-23 17:38:21

他指的是在内存中存储整数的两种不同方法。他提出了两种方法:

  1. 将数字存储在计算机内部使用的基数中
  2. 将数字存储为基数 10(人类使用的基数)。

显然,第一种方法的性能更好,但您的所有问题似乎都与第二种存储数字的形式有关,这对于计算机使用来说是一种非常不寻常的方法(但在人类可读的源文件中看到并不罕见)。

忽略方法1,只考虑方法2,他进一步将其分为两个子类:固定宽度和可变宽度。在固定宽度中,您可以选择一些大小限制,例如 10 位数字,如果小于则用零填充。使用此系统,12345 将表示为 ASCII 字符串:

0000012345

使用可变长度系统,您可以选择一些分隔符,例如分号。这允许您存储任何大小的整数:

12345;

计算机内部通常不会以这种形式存储数字。现代处理器支持的整数运算都要求使用计算机的默认基数来存储数字。如果您愿意,您可以将其视为二进制或十六进制,但实际上这些只是更人性化的表示数据的方式,以便我们更容易思考它。通常,现代计算机处理更大的数据块,例如一次 32 位。

He is referring to two different ways to store an integer in memory. He suggests two methods:

  1. storing the number in the base that the computer internally uses
  2. storing the number as base 10 (the base humans use).

Clearly the first is better for performance, but all your questions seem to relate to the second form of storing numbers which is a very unusual method for a computer to use (but not unusual to see in human readable source files).

Ignoring method 1 and considering only method 2, he further splits this into two subcategories: fixed width and variable width. In fixed width, you choose some limit to the size, for example 10 digits, and pad with zeros if it is less. With this system 12345 would be represented as an ASCII string:

0000012345

With a variable length system, you choose some delimiter, for example semicolon. This allows you to store integers of any size:

12345;

Computers do not typically store numbers in this form internally. The integer operations that modern processors support all require numbers to be stored using the computer's default base. You can think of it as being binary or hexadecimal if you wish, but actually these are just more human ways to represent the data to make it easier for us to think about it. Typically modern computers operate on larger chunks of data, for example 32 bits at a time.

随梦而飞# 2024-08-23 17:38:21

我明白你为什么遇到麻烦了。我建议你再找一本书。这个非常非常难以解释。

“可用于表示数字的位数是有限的”

二进制数有多少位? 32?这是一个限制。

“我不知道他想说什么。零或空格的 ASCII 码。”

0x20 中空格的 ASCII 代码。零的 ASCII 码是 0x30

http://www.asciitable.com/

”解决第一个问题,您总是可以同意使用固定数量的字节,也许可以在左侧用 ASCII 代码填充零或空格。”

没有多大意义。第一个问题是局限性。假设是针对第二个问题,它是这样完成的:

0x30 0x30 0x37 == 7。固定长度为3,在左侧用ASCII零填充。这是数字的标准 COBOL 表示形式——左侧用前导零填充的字符串。 (COBOL 通常使用尾随符号字符)。

“或者,您可以使用可变数量的字节,但同意该数字以数字的最后一个 ASCII 代码结尾,即以非数字终止字符串。”

数字 1,234,456,890,123 (相当大的数字)可能是

0x20 0x31 0x32 0x33 0x34 0x34 0x35 0x36 0x38 0x39 0x30 0x31 0x32 0x33 0x00

它有一个前导空格,使其为正数。它以非数字 (0x00) 结尾。

I can see why you're having trouble. I suggest you find another book. This one is very, very hard to interpret.

"the number of bits available for representing a number is limited"

How many bits in a binary number? 32? That's a limit.

"I've no clue about what he wants to say. ASCII codes for zeros or spaces."

The ASCII code for space in 0x20. The ASCII code for zero is 0x30

http://www.asciitable.com/

"To solve the first problem, you could always agree to use a fixed number of bytes, perhaps padding on the left with ASCII codes for zeros or spaces."

Does not make a lot of sense. The first problem is limitations. Assuming it's for the second problem, it's done like this:

0x30 0x30 0x37 == 7. Fixed length of 3, padded on the left with ASCII zeroes. This is the standard COBOL representation of numbers -- strings of characters padded on the left with leading zeroes. (COBOL often uses a trailing sign character).

"Alternatively, you could use a variable number of bytes, but agree that the number ends with the last ASCII code for a digit, that is, terminating the string with a nondigit."

The number 1,234,456,890,123 (quite a large number) could be

0x20 0x31 0x32 0x33 0x34 0x34 0x35 0x36 0x38 0x39 0x30 0x31 0x32 0x33 0x00

It has a leading space, making it positive. It ends with a non-digit (0x00).

戴着白色围巾的女孩 2024-08-23 17:38:21

这不是一个答案,只是一些您可能想忽略的建议。通过查阅有关 IEEE 754(浮点数表示)和 BCD(二进制编码的十进制——与 ASCII 不同,而是另一种类似的方法)的维基百科文章来补充您的阅读。这些将阐明问题并提供一些解决方案。

Not an answer as such, just some advice which you may want to ignore. Supplement your reading with a trip to Wikipedia articles on IEEE 754 (floating-point number representation) and on BCD (binary-coded decimal -- not the same thing as your ASCII but another similar approach). These will throw light on the problems and some solutions to them.

勿挽旧人 2024-08-23 17:38:21

要了解计算机如何操作数据,我们必须首先了解计算机如何表示数据。为此,有必要了解一些关键概念:
数基数
十进制 在十进制系统(以 10 为底)中,我们会写出数字 11。
二进制 在八进制(基数为 2)中,外星人会写成 1011。
八进制 在二进制系统(基数为 8)中,计算机将使用 13。
十六进制 在十六进制系统(以 16 为基数)中,数字将为 B !

To understand how computers manipulate data, we must first understand how computers represent data. To do this it is necessary to understand some key concepts:
Number Base
Decimal In the Decimal system (base 10) we would write the number 11.
Binary In the Octal system (base 2) the alien would write 1011.
Octal In the Binary system (base 8) the computer would use 13.
Hexadecimal In the Hexadecimal system (base 16) the number would be B !

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文