标签:style blog class code java ext
以下在编写IC卡项目时出现卡号转换错误时的解决方法,在XE2下测试正常。
================================================
uses math; function HexToDec(Hex : string) : string; var i : integer; res : real; len : integer; begin len := length(Trim(Hex)); for i := 1 to len do begin case Hex[i] of ‘0‘..‘9‘: res := res + strToInt(Hex[i]) * power(16,(len-i)); ‘a‘..‘f‘: res := res + (ord(Hex[i]) - ord(‘a‘) + 10) * power(16,(len-i)); ‘A‘..‘F‘: res := res + (ord(Hex[i]) - ord(‘A‘) + 10) * power(16,(len-i)); end; end; result := FloatToStr(res); end; var CardName : string; sWriteData:array[0..320]of AnsiChar; //16进制卡号 begin CardName := AnsiString(sWriteData1); //如果这里不先转化为AnsiString,则有时能正确转换,有时转换后的结果错误 CardName := HexToDec(CardName); end;
Delphi XE2 16进制转10进制《LceMeaning》,布布扣,bubuko.com
Delphi XE2 16进制转10进制《LceMeaning》
标签:style blog class code java ext
原文地址:http://www.cnblogs.com/LceMeaning/p/3719395.html