Report a bug
		
				If you spot a problem with this page, click here to create a GitHub issue.
		
			Improve this page
		
			Quickly fork, edit online, and submit a pull request for this page.
			Requires a signed-in GitHub account. This works well for small changes.
			If you'd like to make larger changes you may want to consider using
			a local clone.
		
	mir.bitop
This module contains a collection of bit-level operations.
Authors: 
Ilia Ki, Phobos & LDC Authors (original Phobos unittests, docs, conventions).
- enum uintbitElemShift(T : ubyte);
 enum uintbitElemShift(T : byte);
 enum uintbitElemShift(T : ushort);
 enum uintbitElemShift(T : short);
 enum uintbitElemShift(T : uint);
 enum uintbitElemShift(T : int);
 enum uintbitElemShift(T : ulong);
 enum uintbitElemShift(T : long);
- Right shift vallue for bit index to get element's index (5 for uint).
- enum uintbitShiftMask(T : ubyte);
 enum uintbitShiftMask(T : byte);
 enum uintbitShiftMask(T : ushort);
 enum uintbitShiftMask(T : short);
 enum uintbitShiftMask(T : uint);
 enum uintbitShiftMask(T : int);
 enum uintbitShiftMask(T : ulong);
 enum uintbitShiftMask(T : long);
- Bit mask for bit index to get element's bit shift (31 for uint).
- TnTrailingBitsToCount(T)(in Tvalue, in Tpopcnt)
 if (__traits(isUnsigned, T));
- Examples:assert(nTrailingBitsToCount(0xF0u, 3u) == 7); assert(nTrailingBitsToCount(0xE00u, 3u) == 12); foreach(uint i; 1 .. 32) assert(nTrailingBitsToCount(uint.max, i) == i); 
- TnLeadingBitsToCount(T)(in Tvalue, in Tpopcnt)
 if (__traits(isUnsigned, T));
- Examples:assert(nLeadingBitsToCount(0xF0u, 3u) == 32 - 5); assert(nLeadingBitsToCount(0x700u, 3u) == 32 - 8); foreach(uint i; 1 .. 32) assert(nLeadingBitsToCount(uint.max, i) == i); 
- autobt(Field, T = typeof(Field.init[size_t.init]))(auto ref Fieldp, size_tbitnum)
 if (__traits(isUnsigned, T));
- Tests the bit.Returns:A non-zero value if the bit was set, and a zero if it was clear.Examples:size_t[2] array; array[0] = 2; array[1] = 0x100; assert(bt(array.ptr, 1)); assert(array[0] == 2); assert(array[1] == 0x100); 
- autobta(Field, T = typeof(Field.init[size_t.init]))(auto ref Fieldp, size_tbitnum, boolvalue)
 if (__traits(isUnsigned, T));
- Tests and assign the bit.Returns:A non-zero value if the bit was set, and a zero if it was clear.
- autobtc(Field, T = typeof(Field.init[size_t.init]))(auto ref Fieldp, size_tbitnum)
 if (__traits(isUnsigned, T));
- Tests and complements the bit.Returns:A non-zero value if the bit was set, and a zero if it was clear.
- autobtr(Field, T = typeof(Field.init[size_t.init]))(auto ref Fieldp, size_tbitnum)
 if (__traits(isUnsigned, T));
- Tests and resets (sets to 0) the bit.Returns:A non-zero value if the bit was set, and a zero if it was clear.
- autobts(Field, T = typeof(Field.init[size_t.init]))(auto ref Fieldp, size_tbitnum)
 if (__traits(isUnsigned, T));
- Tests and sets the bit.Parameters:Field pa non-NULL field / pointer to an array of unsigned integers. size_t bitnuma bit number, starting with bit 0 of p[0], and progressing. It addresses bits like the expression: p[index / (T.sizeof*8)] & (1 << (index & ((T.sizeof*8) - 1)))Returns:A non-zero value if the bit was set, and a zero if it was clear.Examples:size_t[2] array; array[0] = 2; array[1] = 0x100; assert(btc(array.ptr, 35) == 0); if (size_t.sizeof == 8) { assert(array[0] == 0x8_0000_0002); assert(array[1] == 0x100); } else { assert(array[0] == 2); assert(array[1] == 0x108); } assert(btc(array.ptr, 35)); assert(array[0] == 2); assert(array[1] == 0x100); assert(bts(array.ptr, 35) == 0); if (size_t.sizeof == 8) { assert(array[0] == 0x8_0000_0002); assert(array[1] == 0x100); } else { assert(array[0] == 2); assert(array[1] == 0x108); } assert(btr(array.ptr, 35)); assert(array[0] == 2); assert(array[1] == 0x100); 
- Tctpop(T)(in Tsrc)
 if (__traits(isUnsigned, T));
- The 'ctpop' family of intrinsics counts the number of bits set in a value.
- Tctlz(T)(in Tsrc)
 if (__traits(isUnsigned, T));
- The 'ctlz' family of intrinsic functions counts the number of leading zeros in a variable. Result is undefined if the argument is zero.Examples:assert(ctlz(cast(ubyte) 0b0011_1111) == 2); assert(ctlz(cast(ushort) 0b0000_0001_1111_1111) == 7); 
- Tctlzp(T)(in Tsrc)
 if (__traits(isUnsigned, T));
- The 'ctlzp' family of intrinsic functions counts the number of leading zeros in a variable. Result is properly defined if the argument is zero.Examples:assert(ctlzp(cast(ubyte) 0b0000_0000) == 8); assert(ctlzp(cast(ubyte) 0b0011_1111) == 2); assert(ctlzp(cast(ushort) 0b0000_0001_1111_1111) == 7); assert(ctlzp(cast(ushort) 0) == 16); assert(ctlzp(cast(ulong) 0) == 64); 
- Tcttz(T)(in Tsrc)
 if (__traits(isUnsigned, T));
- The 'cttz' family of intrinsic functions counts the number of trailing zeros. Result is undefined if the argument is zero.Examples:assert(cttzp(cast(ubyte) 0b11111100) == 2); assert(cttzp(cast(ushort) 0b1111111110000000) == 7); 
- Tcttzp(T)(in Tsrc)
 if (__traits(isUnsigned, T));
- The 'cttz' family of intrinsic functions counts the number of trailing zeros. Result is properly defined if the argument is zero.Examples:assert(cttzp(cast(ubyte) 0b0000_0000) == 8); assert(cttzp(cast(ubyte) 0b11111100) == 2); assert(cttzp(cast(ushort) 0b1111111110000000) == 7); assert(cttzp(cast(ushort) 0) == 16); assert(cttzp(cast(ulong) 0) == 64); 
Copyright © 2016-2023 by Ilya Yaroshenko | Page generated by
Ddoc on Mon Nov  6 15:24:34 2023