16进制:$//strtoint()//IntToHex

解决方案 »

  1.   

    补充:如果用字符表示的十六进制字符串,可以用hextobin转换。
    delphi中没有2进制的类或函数吧?要用就自己写了
      

  2.   

    十进制转换为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;如何把一个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; 
    这样的答案你是否可以给我加分呢?
      

  3.   

    16->10
    StrToInt('$'+'B4')
    10->16
    IntToHex 函数
    16->2
    HexToBin 函数
      

  4.   

    玉龙的方法行不通呢?我的是Delphi6.0
    shl的运行结果有问题,不过我已经自己搞定了10到2的转换
    你的16到10的方法非常有缺陷,因为你用integer作为参数,根本就不能输a,b,c,d,e,f这几个数,所以不行。
    系统提供的strToInt,IntToHex,HexToBin使用是不能运行通过,说是没有作为override的原函数,莫名其妙,我直接拷贝的他的例子来运行都这个样子
      

  5.   

    //无限进制转换uses
      Math;const
      cScaleChar = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';function IntToDigit(mNumber: Integer; mScale: Byte; mLength: Integer = 0): string;
    var
      I, J: Integer;
    begin
      Result := '';
      I := mNumber;
      while (I >= mScale) and (mScale > 1) do begin
        J := I mod mScale;
        I := I div mScale;
        Result := cScaleChar[J + 1] + Result;
      end;
      Result := cScaleChar[I + 1] + Result;
      if mLength > 0 then
        for I := 1 to mLength - Length(Result) do
          Result := '0' + Result;
    end; { IntToDigit }function DigitToInt(mDigit: string; mScale: Byte): Integer;
    var
      I: Byte;
      L: Integer;
    begin
      Result := 0;
      L := Length(mDigit);
      for I := 1 to L do
        Result := Result + (Pos(mDigit[L - I + 1], cScaleChar) - 1) *
          Trunc(IntPower(mScale, I - 1));
    end; { DigitToInt }