function uhfHexCharToBin(Hex: AnsiChar): AnsiString;
begin
case Hex of
'0': Result := '0000';
'1': Result := '0001';
'2': Result := '0010';
'3': Result := '0011';
'4': Result := '0100';
'5': Result := '0101';
'6': Result := '0110';
'7': Result := '0111';
'8': Result := '1000';
'9': Result := '1001';
'A', 'a': Result := '1010';
'B', 'b': Result := '1011';
'C', 'c': Result := '1100';
'D', 'd': Result := '1101';
'E', 'e': Result := '1110';
'F', 'f': Result := '1111';
else Result := '';
end;
end;
function uhfBinToInt(const Value: AnsiString): Cardinal
//将二进制字符串转化为整数
var
i: Integer;
begin
Result := 0;
for i := 1 to Length(Value) do
begin
if (Value <> '1') and (Value <> '0') then
begin
Result := 0;
Break;
end;
if Value = '1' then
Result := Result + Round(Power(2, Length(Value) - i));
end;
end;
function uhfHexToInt(const Value: AnsiString): Cardinal
//将十六进制字符串转化为整数
var
i: Integer;
s, sTemp: AnsiString;
begin
Result := 0;
s := '';
for i := 1 to Length(Value) do
begin
sTemp := uhfHexCharToBin(Value);
if sTemp = '' then Exit;
s := s + sTemp;
end;
Result := uhfBinToInt(s);
end;