java - 在 MIPS 中将十六进制转换为十进制
问题描述
我将如何将此 Java 代码转换为 MIPS?我很难在 MIPS 中实现“基础”的概念。我将如何使用 mips 并弄清楚它是什么基础?例如,假设我们有 0xFFF、0x3C、0xAA
它会是什么样子?
// Function to convert hexadecimal to decimal
static int hexadecimalToDecimal(String hexVal)
{
int len = hexVal.length();
// Initializing base value to 1, i.e 16^0
int base = 1;
int dec_val = 0;
// Extracting characters as digits from last character
for (int i=len-1; i>=0; i--)
{
// if character lies in '0'-'9', converting
// it to integral 0-9 by subtracting 48 from
// ASCII value
if (hexVal.charAt(i) >= '0' && hexVal.charAt(i) <= '9')
{
dec_val += (hexVal.charAt(i) - 48)*base;
// incrementing base by power
base = base * 16;
}
// if character lies in 'A'-'F' , converting
// it to integral 10 - 15 by subtracting 55
// from ASCII value
else if (hexVal.charAt(i) >= 'A' && hexVal.charAt(i) <= 'F')
{
dec_val += (hexVal.charAt(i) - 55)*base;
// incrementing base by power
base = base*16;
}
}
return dec_val;
}
解决方案
推荐阅读
- java - 通过 TLS 与外部系统握手时如何启用椭圆曲线扩展?
- mysql - Sequelize 在种子运行时插入新记录而不是更新以前的记录
- swiftui - geometryReader 滑动时图像闪烁
- c++ - 堆排序 C++ 调试
- windows - 如何检查 IIS APP 是否在调试模式下生成
- ruby-on-rails - 弹性搜索边缘图未正确搜索
- javascript - 如何获取 JSON(来自 Dynamics 365 Business Central API 的 OData)并访问其元素以在本地存储
- assembly - 尝试使用系统调用 gettimeofday() 在 armv7l 上的汇编中获取伪随机数,但系统调用上的寄存器变为 0?
- google-analytics - 特定浏览量序列的平均页面停留时间
- .net - 是否可以在模块中使用 DefaultParameterValue?