std.bitmanip
Bit-level manipulation facilities. License:Boost License 1.0. Authors:
Walter Bright, Andrei Alexandrescu Copyright Digital Mars 2007 - 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
- Allows creating bit fields inside structs and classes.
Example:
struct A { int a; mixin(bitfields!( uint, "x", 2, int, "y", 3, uint, "z", 2, bool, "flag", 1)); } A obj; obj.x = 2; obj.z = obj.x;
The example above creates a bitfield pack of eight bits, which fit in one ubyte. The bitfields are allocated starting from the least significant bit, i.e. x occupies the two least significant bits of the bitfields storage. The sum of all bit lengths in one bitfield instantiation must be exactly 8, 16, 32, or 64. If padding is needed, just allocate one bitfield with an empty name. Example:
struct A { mixin(bitfields!( bool, "flag1", 1, bool, "flag2", 1, uint, "", 6)); }
The type of a bit field can be any integral type or enumerated type. The most efficient type to store in bitfields is bool, followed by unsigned types, followed by signed types. - Allows manipulating the fraction, exponent, and sign parts of a
float separately. The definition is:
struct FloatRep { union { float value; mixin(bitfields!( uint, "fraction", 23, ubyte, "exponent", 8, bool, "sign", 1)); } enum uint bias = 127, fractionBits = 23, exponentBits = 8, signBits = 1; }
- Allows manipulating the fraction, exponent, and sign parts of a
double separately. The definition is:
struct DoubleRep { union { double value; mixin(bitfields!( ulong, "fraction", 52, ushort, "exponent", 11, bool, "sign", 1)); } enum uint bias = 1023, signBits = 1, fractionBits = 52, exponentBits = 11; }
- An array of bits.
- Support for [index] operation for BitArray.
- Support for array.dup property for BitArray.
- Support for foreach loops for BitArray.
- Support for array.reverse property for BitArray.
- Support for array.sort property for BitArray.
- Support for operators == and != for bit arrays.
- Implement comparison operators.
- Set BitArray to contents of ba[]
- Map BitArray onto v[], with numbits being the number of bits in the array. Does not copy the data. This is the inverse of opCast.
- Convert to void[].
- Support for unary operator ~ for bit arrays.
- Support for binary operator & for bit arrays.
- Support for binary operator | for bit arrays.
- Support for binary operator ^ for bit arrays.
- Support for binary operator - for bit arrays. a - b for BitArrays means the same thing as a & ~b.
- Support for operator &= bit arrays.
- Support for operator |= for bit arrays.
- Support for operator ^= for bit arrays.
- Support for operator -= for bit arrays. a -= b for BitArrays means the same thing as a &= ~b.
- Support for operator ~= for bit arrays.
- Support for binary operator ~ for bit arrays.