如何把一个16进制字符转换为10进制?
(1)方法1
Function HexToDec(const Value :Integer ) : string;
var
s : string;
begin
  s := '$' + IntToStr(Value);
  Result := InToStr(StrToInt(s));
end;(2)方法2
Funtion HexToDec(const Value :Integer) : string;
CONST HEX : ARRAY['A'..'F'] OF INTEGER = (10,11,12,13,14,15);
VAR
  str : String;
  In : Integer;
  i : integer;
BEGIN
  Str := UpperCase(IntToStr(Value));
  Int := 0;
  FOR i := 1 TO Length(str) DO
    IF str[i] < 'A' THEN
    Int := Int * 16 + ORD(str[i]) - 48
  ELSE
    Int := Int * 16 + HEX[str[i]];
  
  Result := IntToStr(Int);
end; 

解决方案 »

  1.   

    十进制转换为2进制?
    function DecToBinStr(n: integer): string;
    var
      S: string;
      i: integer;
      Negative: boolean;
    begin
      if n < 0 then 
        Negative := true
    else
        Negative := False;  n := Abs(n);
      for i := 1 to SizeOf(n) * 8 do
      begin
         if n < 0 then 
          S := S + '1' 
       else 
          S := S + '0';     n := n shl 1;
      end;
      Delete(S,1,Pos('1',S) - 1);//remove leading zeros
      if Negative then 
         S := '-' + S;
      Result := S;
    end;