hjy : integer; 
hjy2 : string; hjy2 := inttohex(hjy,4); 假如hjy2得到的结果是 1A 01,那如果我现在要得到hjy2的高字节和低字节,好办,分别为 1A 01 
那现在的问题是假如hjy2得到的结果是 00 01 1A 01,叫法是不是溢出?不管了,那如果我现在要得到hjy2的高字节和低字节,怎么取啊,不会还是 1A 01 吧,前面所谓溢出的 00 01 不管了吗?

解决方案 »

  1.   

     00 01 1A 01
    你这里总共好像才4byte  不知道你所谓讲的溢出是什么意思?  integer也是4byte的。
      

  2.   

    integer是从有符号到无符号FF FF 1A 01 这个应该会截取
      

  3.   

    IntToHex(Value: Integer; Digits: Integer): string; overload; 
    hjy2 := inttohex(hjy,4);
    你这里指定的4是在hjy不足4位的情况下才起作用的(补足4位),如果超过4位你是不用去理会它的。同时它也并不是什么溢出。对应取高低字节和原来4位的取法是一样的。
    用hi(hjy2),lo(hjy2)可以取得对应的高低字节,hiword(hjy2),loword(hjy2)可以取得对应的高低字。
      

  4.   

    procedure TForm11.btn1Click(Sender: TObject);
    const
      Test : DWORD = $12345678;
    var
      pBytes : PByteArray;
    begin
    //  取低字节
      ShowMessage(Format('lowByte = %s',[IntToHex(Lo(Test), 1)]));
    //  取高字节
      ShowMessage(Format('hiByte = %s',[IntToHex(Hi(Test), 1)]));
    //  取低字
      ShowMessage(Format('lowWord = %s',[IntToHex(LoWord(Test), 1)]));
    // 取高字
      ShowMessage(Format('hiWord = %s',[IntToHex(HiWord(Test), 1)]));
    // 在内存里从低向高分别取Dword类型字节码
      pBytes := @Test;
      ShowMessage(Format('byte1 = %s', [Inttohex(pBytes^[0],1)]));
      ShowMessage(Format('byte2 = %s', [Inttohex(pBytes^[1],1)]));
      ShowMessage(Format('byte3 = %s', [Inttohex(pBytes^[2],1)]));
      ShowMessage(Format('byte4 = %s', [Inttohex(pBytes^[3],1)]));
    end;
      

  5.   

    //如果你就是为了取高低位。方法很多。 
    //integer类型,也可以这样取。 
    var 
      b:array[0..3] of byte; 
      i:integer; 
    begin 
      i:=100; 
      move(i,b[0],4); 
    end; 
    //int64类似,改一下就可以了。