最近看到一个协议,它的返回内容中有一项内容‘Func’注明是"位或方式"。Func是一个十进制的值。
其中附带一个编码表(位或方式)。
如:
编码             含义
4                长途
32               短途
64               国际
.                .
.                .
.                . 
33554432         州际 我用测试了2次,得到的Func的值分别是409059,33963499。
我是这样理解的。将返回的Func值转换成二进制,然后看对应位的值。
如编码中'4'代表'长途',就看二进制的Func值第2位是否为1;
  编码中'64'代表'国际',就看二进制的Func值第6为是否为1。
我这样理解对吗?顺便问问十进制转二进制的函数是什么?

解决方案 »

  1.   

    刚刚看了你的上个帖子
    回复你10进制到2进制的转换函数
    --------------------
    // Integer to Binary
    function IntToBin(Value: Longint; Digits: Integer): string;
    var
      i: Integer;
    begin
      Result := '';
      for i := Digits downto 0 do
        if Value and (1 shl i) <> 0 then
          Result := Result + '1'
        else
          Result := Result + '0';
    end;
      

  2.   

    这个函数也可以帮你实现进制转换(参数不同而已)
    ------------------------
    function IntToBinaryStr(TheVal: LongInt): string;
    var
      counter: LongInt;
    begin
      if TheVal = 0 then 
      begin
        result := '0';
        exit;
      end;
      result := '';
      counter := $80000000;
      while ((counter and TheVal) = 0) do 
      begin
        counter := counter shr 1;
        if (counter = 0) then 
          break;
      end;
      while counter > 0 do 
      begin
        if (counter and TheVal) = 0 then 
          result := result + '0'
        else 
          result := result + '1';
        counter := counter shr 1;
      end;
    end;