伪码:
function DecodeULEB128(var AULEB128: UInt64): UInt64;
var
lShift : Cardinal;
lByte : Byte;
begin
Result := 0;
lShift = 0;
while true do
begin
lByte := next byte of AULEB128;
Result = Result or (low order 7 bits of lByte << lShift);
if (high order bit of lByte = 0) then
break;
Inc(lShift, 7);
end;
end;我有两个问题:
1)如何访问AULEB128的字节,以便将其中的一个分配给lByte?
2)如何访问Byte的低阶/高阶位?
我知道如何使用SysUtils中定义的记录来访问低阶/高阶位:
WordRec = packed record
case Integer of
0: (Lo, Hi: Byte);
1: (Bytes: array [0..1] of Byte);
end;
LongRec = packed record
case Integer of
0: (Lo, Hi: Word);
1: (Words: array [0..1] of Word);
2: (Bytes: array [0..3] of Byte);
end;
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;我习惯于这样做: Int64Rec(Var).Lo。
我是否必须使用字节上的and运算符来访问一些?
发布于 2017-01-27 22:21:19
试着做这样的事情:
function DecodeULEB128(AULEB128: UInt64): UInt64;
var
I, lShift : Integer;
lByte : Byte;
begin
Result := 0;
lShift := 0;
for I := 0 to 7 do
// or maybe 'for I := 7 downto 0' instead?
// Not sure which direction you should be looping...
begin
lByte := Int64Rec(AULEB128).Bytes[I];
Result := Result or (UInt64(lByte and $7F) shl lShift);
if (lByte and $80) = 0 then
Break;
Inc(lShift, 7);
end;
end;https://stackoverflow.com/questions/41901668
复制相似问题