将十六进制字符转换为 MIPS 中的十进制等效值
如何获取单个 ASCII 字符并将其转换为 MIP 中的十进制等效值?
我是否只需要满足一些条件即可从 ascii 代码中减去一定数量以使其成为十进制表示形式?
How do I take a single ASCII character and convert it to its decimal equivelant in MIPs?
Do I simply have to have some conditions to subtract a certain amount from the ascii code to make it its decimal representation?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
应检查单个十六进制字符是否在
其他任何内容都是错误。 如果它确实落入这些范围之一,请执行以下操作:
如果您确定非十进制数字的字符始终为大写,则可以跳过上面每个列表中的第三步,但不需要大量额外的代码来完成此操作。
A single hex character should be checked if it's in the range
Anything else is an error. If it does fall within one of those ranges, perform the following:
If you're certain that the character will always be uppercase for the non-decimal digits, you can skip the third step in each of those lists above but it doesn't require a lot of extra code to do it.
这是 Pax 所写内容的简单实现(假设十六进制数字 - A 到 F 始终为大写)
文件 hextodec.c
文件 hextodec.S
测试运行
Here's a simplistic implementation of what Pax wrote (it assumes that hexadecimal digits - A to F are always upper case)
File hextodec.c
File hextodec.S
test run
是的,从 ASCII 值中减去 48 可能是最简单的。
Yes subtracting 48 from the ASCII value will probably be easiest.