JCL Help:ReverseBits@Byte
JCL Help: ReverseBits Function
Search in JCL Help
Search in all projects
Summary
Reverses the bits of Value.
Pascal
function ReverseBits(Value: Byte): Byte; overload;
function ReverseBits(Value: Shortint): Shortint; overload;
function ReverseBits(Value: Smallint): Smallint; overload;
function ReverseBits(Value: Word): Word; overload;
function ReverseBits(Value: Integer): Integer; overload;
function ReverseBits(Value: Cardinal): Cardinal; overload;
function ReverseBits(Value: Int64): Int64; overload;
function ReverseBits(P: Pointer; Count: Integer): Pointer; overload;
Parameters
Parameters | Description |
Value: Byte | The integer type whose bits to reverse. |
P: Pointer | Address of a buffer whose bits to reverse. |
Count: Integer | Size of the buffer, in bytes, specified by P. |
Return Value
Copy of Value with it's bits reversed.
Description
ReverseBits reverses the bits in the passed parameter. That is, assuming a byte, bit 0 is swapped with bit 7, bit 1 is swapped with bit 6 and so on. This function exists in 5 forms, one for each Integer type. The last overload is a generalisation of this which reverses the bits in the supplied buffer. Note that all overloads use a table based approach to reversing the bits. The simple types overloads use only a 15 byte table while the pointer overload uses a 255 byte table. Due to this the pointer overload is much faster when used on large buffers.
About
Unit
Donator
Team JCL
Notes
Warning Keep in mind that some of the ReverseBits overloads accept signed integers as their argument but that reversing the bits of a signed integer is somewhat akward. Be sure that you understand the meaning of reversing the bits in a signed integer and that's what you want. The pointer returned by the Pointer overload points to the same buffer passed in as it's argument, iow it's not a newly allocated buffer. The ReverseBits(Pointer, Integer) overload was originally written by Mike Lischke. Reversing is not the same as toggling. To toggle bits use the ToggleBit function.
Contribute to this help topic
This documentation wiki is based on the collaborative effort of Project JEDI users. Your edits are welcome in order to improve documentation quality: edit this page