I am pulling data from a .txt file byte by byte using delphi. For each byte, I need to swap the beginning and the ending bits of that byte. I've been searching google for hours but I can't find any reference about manipulating bits inside byte vars in delphi. Any ideas?
b := (b and $7E) or (b shr 7) or (b shl 7);
First we keep the middle 6 bits, then swaps the MSB and the LSB bits in register shift operations.
Bit manipulation in Delphi is fun. There are many options, and this is a straight forward solution. David proposes a LUT solution which can be faster (only by a tiny bit though).
There was an interesting similar question about bit-reflecting a whole byte, see How can I bit-reflect a byte in Delphi?
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With