delphi – 我不能使用带有int64变量的SHL(向左移位)
发布时间:2020-12-15 04:08:44 所属栏目:大数据 来源:网络整理
导读:Result:= b8; Result:= Result+ (b7 SHL 8); Result:= Result+ (b6 SHL 16); Result:= Result+ (b5 SHL 24); Result:= Result+ (b4 SHL 32); Result:= Result+ (b3 SHL 40); ------ here Result:= Result+ (b2 SHL 48); Result:= Result+ (MSB SHL 56); (结
Result:= b8; Result:= Result+ (b7 SHL 8); Result:= Result+ (b6 SHL 16); Result:= Result+ (b5 SHL 24); Result:= Result+ (b4 SHL 32); Result:= Result+ (b3 SHL 40); <------ here Result:= Result+ (b2 SHL 48); Result:= Result+ (MSB SHL 56); (结果是int64,b1-b8是字节). 但编译器抱怨“常量exp违反了子范围”. 编辑: EDIT2: 解决方法
我会避免所有算术运算(你的代码有添加和移位),并且这样做:
Int64Rec(Result).Bytes[0] := b8; Int64Rec(Result).Bytes[1] := b7; //etc. Int64Rec在SysUtils中定义如下: Int64Rec = packed record case Integer of 0: (Lo,Hi: Cardinal); 1: (Cardinals: array [0..1] of Cardinal); 2: (Words: array [0..3] of Word); 3: (Bytes: array [0..7] of Byte); end; 如果您将字节存储在一个数组中,那么您可以将它全部包装在for循环中. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |