如: 定义了一个 a: Integer数.
如何在表单程序中, 把a数的高字节和低字节转化过来?我有使用了Swap函数来做, 但是提示如下信息:
Statement expected, but expression of type 'Integer' found.
????????????????????????????????

解决方案 »

  1.   

    Swap函数只支持16位整数的高、低字节交换。可以用下面的函数:function SwapLongWord(Value: LongWord): LongWord;
    var
      i     : Integer;
      pA, pB: PByte;
    begin
      pA := @Value;
      pB := @Result;
      inc(pA, SizeOf(LongWord) - 1);
      for i := 1 to SizeOf(LongWord) do
      begin
        pB^ := pA^;
        dec(pA);
        inc(pB);
      end;
    end;
      

  2.   

    什么意思? 有点看不懂!
    有要的是Integer的类型, 不是LongWord类型!
      

  3.   

    Integer和LongWord都是32位整数类型,可以相互转换的(强类型转换即可)。
    至于看不懂,那只能介绍你先学习一下指针操作了。
      

  4.   

    一个integer四字节,是交换高低字节,还是高低字,或者字节全部反序?
      

  5.   

    x:= i shr 16 + (i and #ff )  shl 16
      

  6.   

    如果是四个字节全逆序
    function Swap32(const Input:Integer):Integer;
    asm
      BSWAP eax {486+}
    end;
      

  7.   

    function SwapHighLowByte(Value: LongWord): LongWord;
    begin
      Result := (Value shr 24) or (Value shl 24) or (Value and $00ffff00);
    end;
      

  8.   

    上面的vividw
    x:= i shr 16 + (i and $ff)  shl 16 我有点明白你的意思, 但是Integer是在delphi中占4个字节!
    $ff ???? 这样对吗?
      

  9.   

    楼主应该把问题说明白。一个四字节,把高低位调换,具体如何调应该有一个比较明确地说明。首先具体是高低字节调换还是高低字调用。1.高低字调换
    ((x and $ffff) shr 16) or ((x shl 16) and $ffff)2. 第一字节和第四字节调换
    ((x and $ff) shr 24) or ((x shl 24) and $ff) and (x and $ffff00)3. 字节序逆转(“一,二,三,四”转换为“四,三,二,一”)
    可以使用我上面的方法,那个只是一条汇编指令,效率比位操作要高得多