Dint:=(fbuf[p] shl 56) or (fbuf[p+1] shl 48) or (fbuf[p+2] shl 40) or (fbuf[p+3] shl 32) or (fbuf[p+4] shl 24) or (fbuf[p+5] shl 16) or (fbuf[p+6] shl 8) or fbuf[p+7];
(Dint:int64  fbuf:array of byte)
p:=p+8;
这样编译时提示出错信息:"Constant expression violates subrange bounds"
错在那串表达式
是怎么回事
帮帮忙~~看一下

解决方案 »

  1.   

    byte 不能  shl 56 吧!
    总共就8位哦~~~~~
      

  2.   

    可是我在转成integer时(int)
    int:=(fbuf[p] shl 24) or (fbuf[p+1] shl 16) or (fbuf[p+2] shl 8) or fbuf[p+3];
    能通过啊~不错啊~
    好奇怪
      

  3.   

    将二进制的8个字节转换成int64
      

  4.   

    >可是我在转成integer时(int)
     int:=(fbuf[p] shl 24) or (fbuf[p+1] shl 16) or (fbuf[p+2] shl 8) or fbuf[p+3];
     能通过啊~不错啊~这是因为byte类型最多只能 shl 32,超过就会出错。
      

  5.   

    TBytes = array of Byte;function ToBytes(const AValue: Int64): TBytes ; overload;
    begin
      {$IFDEF DotNet}
      Result := System.BitConverter.GetBytes(AValue);
      {$ELSE}
      SetLength(Result, SizeOf(Int64));
      PInt64(@Result[0])^ := AValue;
      {$ENDIF}
    end;function BytesToInt64(const AValue: TBytes ): Int64;
    begin
      {$IFDEF DotNet}
      Result := System.BitConverter.ToInt64(AValue,0);
      {$ELSE}
      Result := PInt64(@AValue[0])^;
      {$ENDIF}
    end;
      

  6.   

    这样就可以(先将fbuf[x]转成int64) 
    Dint:=(int64(fbuf[p]) shl 56) or (int64(fbuf[p+1]) shl 48) or (int64(fbuf[p+2]) shl 40) or (int64(fbuf[p+3]) shl 32) or (int64(fbuf[p+4]) shl 24) or (int64(fbuf[p+5]) shl 16) or (int64(fbuf[p+6]) shl 8) or int64(fbuf[p+7]);
      

  7.   

    function Swap64(const Value: array of Byte): Int64;
    asm
    MOV EDX, [EAX];
      MOV EAX, [EAX + 4];  BSWAP EDX;
      BSWAP EAX;
    end;procedure Test;
    var
      a: array of Byte;
      i: integer;
      i64: Int64;
    begin
      SetLength(a, 8);
      for i := 0 to 7 do
        a[i] := (i + 1) * $11;
      i64 := Swap64(a);
      dialogs.ShowMessage(IntToHex(i64, 8));
    end;
      

  8.   

    直接CopyMemory,按位对齐就好。