我是一个编程新手所以请你好:) 我刚写了一个程序,它将十六进制String转换为dec int。我用“负”十六进制来测试它,有些值是正确的,有些是错误的。我无法用错误的输出解决问题。
这是我的代码:
String abc = "0123456789ABCDEF";
String hexString = "-ffad";
int decResult = 0;
//int endRes = 0;
hexString = hexString.toUpperCase();
for(int i = 0; i < hexString.length(); i++)
{
if(hexString.contains("-"))
{
hexString = hexString.replace("-", "");
char res = hexString.charAt(i);
int d = abc.indexOf(res);
decResult = (16*decResult + d)*(-1);
}
else
{
char res = hexString.charAt(i);
int d = abc.indexOf(res);
decResult = ((16*decResult) + d)*1;
}
}
System.out.println(decResult);
答案 0 :(得分:1)
因为你这样做
Function SplitCaps(strIn As String) As String
Dim objRegex As Object
Set objRegex = CreateObject("vbscript.regexp")
With objRegex
.Global = True
.Pattern = "([a-z])([A-Z])"
SplitCaps = Replace(.Replace(strIn, "$1, $2"), "<br>", ", ")
End With
End Function
对于 hexString 字符串中的每个字符,然后转换的最终符号将计算为
改进的工作解决方案可以是:
if(hexString.contains("-"))