How can I bit-reflect a byte in Delphi?
问题 Is there an easy way to bit-reflect a byte variable in Delphi so that the most significant bit (MSB) gets the least significant bit (LSB) and vice versa? 回答1: In code you can do it like this: function ReverseBits(b: Byte): Byte; var i: Integer; begin Result := 0; for i := 1 to 8 do begin Result := (Result shl 1) or (b and 1); b := b shr 1; end; end; But a lookup table would be much more efficient, and only consume 256 bytes of memory. function ReverseBits(b: Byte): Byte; inline; const Table: