QOJ.ac

QOJ

Límite de tiempo: 1 s Límite de memoria: 256 MB Puntuación total: 100

#5619. 浮点数格式转换

Estadísticas

为了支持一项专利辩护,我们需要恢复一些存储在已停用的 Gould Power-Node 小型机上的单精度浮点实验数据。Gould 使用的是一种 16 进制浮点格式。我们希望尽可能地将 Gould 浮点值转换为 IEEE 单精度浮点值。

Gould 内部浮点格式包含 1 位符号位 $S$、7 位偏移(基数为 16)指数域 $E$ 以及 24 位(6 个十六进制位)尾数。(注意,这意味着尾数的高 3 位可能为零。)

$$\text{value} = ((-1)^S)((16)^{(E-64)})(\text{MANTISSA} / (2^{24}))$$

浮点零由 32 位 0 表示。

IEEE 格式包含 1 位符号位 $S$、8 位偏移(基数为 2)指数域 $E$ 以及 24 位尾数,其中高位(在规格化数中)始终为 1,且不包含在 23 位的格式中。

如果指数不为 255 且不为 0,则该值为规格化浮点数,

$$\text{value} = ((-1)^S)((2)^{(E-127)})(1 + (\text{MANTISSA} / (2^{23})))$$

如果指数为 255 且尾数为 0,则该值为正无穷或负无穷(取决于符号位)。如果指数为 255 且尾数不为 0,则表示本题中不会使用的特殊值。

如果指数为 0 且尾数为 0,则该值为正零或负零(取决于符号位)。

如果指数为 0 且尾数不为 0,则该值为非规格化浮点数,

$$\text{value} = ((-1)^S)((2)^{(-126)})(\text{MANTISSA} / (2^{23}))$$

编写一个程序,输入 Gould 格式的浮点值,并按以下规则输出 IEEE 格式的值:

如果值为零,返回(正)零。

如果值太大而无法表示为规格化浮点数,则根据符号返回正无穷或负无穷。

如果值太小而无法表示为规格化浮点数: 如果它可以表示为非规格化浮点数,则返回非规格化值。 否则,根据符号返回正零或负零。

在所有其他情况下,返回规格化值。

如果有效位数少于 IEEE 浮点数所需位数,则用 0 补齐。 如果有效位数多于 IEEE 浮点数所需位数,则截断多余位数。

输入格式

输入的第一行包含一个整数 $P$ ($1 \le P \le 1000$),表示后续的数据集数量。每个数据集应独立处理。

每个数据集由单行输入组成。它包含数据集编号 $K$,后跟 8 个十六进制数字($0-9, A-F$),表示 Gould 浮点值。

输出格式

每个数据集输出一行。输出行包含数据集编号 $K$,后跟一个空格,以及 8 个十六进制数字($0-9, A-F$),表示对应的(如上所述)IEEE 浮点值。

样例

样例输入 1

4
1 41200000
2 E0FFFFFE
3 E11FFFFF
4 88888888

样例输出 1

1 40000000
2 FF7FFFFE
3 FF800000
4 80000000

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.