我从串口读入了一个长度为40byte的数组,如0101011110000.....,实际上是由AA(标识符)+16位的实型数+16位的实型数组成的,怎么样从那个40byte长的数组里把两个16位的实型数解出来?

解决方案 »

  1.   

    最笨的办法:直接读
    for i:=8 to 24 do
    b[i-9]:=a[i]
      

  2.   

    我的意思是如何将16个bit的二进制数转换为WORD类型
      

  3.   

    Delphi syntax:procedure BinToHex(Buffer, Text: PChar; BufSize: Integer);C++ syntax:extern PACKAGE void __fastcall BinToHex(char *Buffer, char *Text, int BufSize);DescriptionCall BinToHex to convert the binary value in a buffer into a string that is its hexadecimal representation.Buffer is a buffer of bytes that contains the binary value.Text returns a null-terminated string that represents the value of Buffer as a hexadecimal number.BufSize is the size of Buffer. Text needs to point to a sequence of characters that has at least 2*BufSize bytes because each hexadecimal character represents two bytes.
      

  4.   

    楼上的怎么只说了要做什么,就没有具体的code出来吗?
    新手我也想看看呢。
      

  5.   

    二进制转十进制
    function binToDec(Value :string) : string;
    var
      str : String;
      int : Integer;
      i : integer;
    begin
      Str := UpperCase(Value);
      Int := 0;
      for i := 1 to Length(str) do
      Int := Int * 2+ ORD(str[i]) - 48;
      Result := IntToStr(Int);
    end;
      

  6.   

    修改一下:
    function binToDec(Value :string) : integer;
    var
      str : String;
      int : Integer;
      i : integer;
    begin
      Str := UpperCase(Value);
      result := 0;
      for i := 1 to Length(str) do
      result := result * 2+ ORD(str[i]) - 48;
    end;procedure TForm1.Button1Click(Sender: TObject);
    var
      s: string;
    begin
      s:= '1000000000001111';
      showmessage(inttostr(bintodec(s)));
    end;