core.bitop
This module contains a collection of bit-level operations. License:Boost License 1.0. Authors:
Don Clugston, Sean Kelly, Walter Bright Copyright Don Clugston 2005 - 2009. Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http:
//www.boost.org/LICENSE_1_0.txt)
- Scans the bits in v starting with bit 0, looking
for the first set bit.
Returns:
The bit number of the first bit set. The return value is undefined if v is zero. - Scans the bits in v from the most significant bit
to the least significant bit, looking
for the first set bit.
Returns:
The bit number of the first bit set. The return value is undefined if v is zero. Example:
import core.bitop; int main() { uint v; int x; v = 0x21; x = bsf(v); printf("bsf(x%x) = %d\n", v, x); x = bsr(v); printf("bsr(x%x) = %d\n", v, x); return 0; }
Output:
bsf(x21) = 0
bsr(x21) = 5 - Tests the bit.
- Tests and complements the bit.
- Tests and resets (sets to 0) the bit.
- Tests and sets the bit.
Parameters:
Returns:uint* p a non-NULL pointer to an array of uints. index a bit number, starting with bit 0 of p[0], and progressing. It addresses bits like the expression: p[index / (uint.sizeof*8)] & (1 << (index & ((uint.sizeof*8) - 1)))
A non-zero value if the bit was set, and a zero if it was clear. Example:
import core.bitop; int main() { uint array[2]; array[0] = 2; array[1] = 0x100; printf("btc(array, 35) = %d\n", <b>btc</b>(array, 35)); printf("array = [0]:x%x, [1]:x%x\n", array[0], array[1]); printf("btc(array, 35) = %d\n", <b>btc</b>(array, 35)); printf("array = [0]:x%x, [1]:x%x\n", array[0], array[1]); printf("bts(array, 35) = %d\n", <b>bts</b>(array, 35)); printf("array = [0]:x%x, [1]:x%x\n", array[0], array[1]); printf("btr(array, 35) = %d\n", <b>btr</b>(array, 35)); printf("array = [0]:x%x, [1]:x%x\n", array[0], array[1]); printf("bt(array, 1) = %d\n", <b>bt</b>(array, 1)); printf("array = [0]:x%x, [1]:x%x\n", array[0], array[1]); return 0; }
Output:
btc(array, 35) = 0 array = [0]:x2, [1]:x108 btc(array, 35) = -1 array = [0]:x2, [1]:x100 bts(array, 35) = 0 array = [0]:x2, [1]:x108 btr(array, 35) = -1 array = [0]:x2, [1]:x100 bt(array, 1) = -1 array = [0]:x2, [1]:x100
- Swaps bytes in a 4 byte uint end-to-end, i.e. byte 0 becomes byte 3, byte 1 becomes byte 2, byte 2 becomes byte 1, byte 3 becomes byte 0.
- Reads I/O port at port_address.
- Writes and returns value to I/O port at port_address.
- Calculates the number of set bits in a 32-bit integer.
- Reverses the order of bits in a 32-bit integer.