仅使用 16 位有符号字的算术
我正在尝试仅使用 16 位有符号字执行算术。我需要能够执行加法、乘法等。
作为示例,我需要减去两个数据值,下面是一个示例: 7269.554688-46.8 或 4385.6616210938 + 32.2
但是,这些值需要转换为 16 位字,然后才能执行减法、乘法或加法。
我还可以使用多个 16 位字来存储一个值。
我将如何执行加法、减法和乘法等运算,以及如何适当地转换所有输入值以使小数点始终正确排列?
I am trying to perform arithmetic using only 16-bit signed words. I need to be able to perform addition, multiplication, etc.
As an example I need to subtract two data values, below is an example:
7269.554688-46.8
or 4385.6616210938 + 32.2
However, these values need to be converted into 16-bit words and then the subtraction, multiplication, or addition can be performed.
I could also use multiple 16-bit words to store one value.
How would I go about performing operations like addition, subtraction and multiplication and how would I convert all of my input values appropriately so that the decimal points always line up properly?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您在哪个平台编码?要执行您作为示例给出的操作,您需要一个浮点单元。浮点数通常通过 32 位或 64 位表示,很少使用 16 位。
如果您没有,并且您拥有的只是 16 位整数的简单运算,您可以模拟浮点单元,但这不是一项简单的任务。
What platform are you coding for? To perform the operations you've given as an example, you would need a floating point unit. Floating point numbers are usually represented through 32 bits or 64 bits, rarely 16 bit.
If you don't have one and all you have are simple operations on 16 bit integers, you could emulate a floating point unit, but that is not a trivial task.