View source code
							
							
						
								Display the source code in std/bitmanip.d from which this
								page was generated on github.
							
						
							Report a bug
							
						
								If you spot a problem with this page, click here to create a
								Bugzilla 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
								local clone.
							
						Struct std.bitmanip.BitArray
A dynamic array of bits. Each bit in a BitArray can be manipulated individually
or by the standard bitwise operators &, |, ^, ~, >>, << and also by
other effective member functions; most of them work relative to the BitArray's
dimension (see dim), instead of its length.
						
				struct BitArray
				;
						
					
				Constructors
| Name | Description | 
|---|---|
| this() | Creates a BitArrayfrom aboolarray, such thatboolvalues read
    from left to right correspond to subsequent bits in theBitArray. | 
| this(v, numbits) | Creates a BitArrayfrom the raw contents of the source array. The
    source array is not copied but simply acts as the underlying array
    of bits, which stores data assize_tunits. | 
Properties
| Name | Type | Description | 
|---|---|---|
| dim[get] | ulong | |
| dup[get] | BitArray | Duplicates the BitArrayand its contents. | 
| length[get] | ulong | |
| length[set] | ulong | Sets the amount of bits in the BitArray.
 Warning: increasing length may overwrite bits in
 the final word of the current underlying data regardless
 of whether it is shared between BitArray objects. i.e. D
 dynamic array extension semantics are not followed. | 
| reverse[get] | BitArray | Reverses the bits of the BitArray. | 
| sort[get] | BitArray | Sorts the BitArray's elements. | 
Methods
| Name | Description | 
|---|---|
| bitsSet() | Return a lazy range of the indices of set bits. | 
| count() | Counts all the set bits in the BitArray | 
| flip() | Flips all the bits in the BitArray | 
| flip(pos) | Flips a single bit, specified by pos | 
| opApply(dg) | Support for foreachloops forBitArray. | 
| opBinary(e2) | Support for binary bitwise operators for BitArray. | 
| opBinary(b) | Support for binary operator ~ for BitArray. | 
| opBinaryRight(b) | Support for binary operator ~ for BitArray. | 
| opCast() | Convert to void[]. | 
| opCast() | Convert to size_t[]. | 
| opCmp(a2) | Supports comparison operators for BitArray. | 
| opEquals(a2) | Support for operators == and != for BitArray. | 
| opIndex(i) | Gets the i'th bit in theBitArray. | 
| opIndexAssign(b, i) | Sets the i'th bit in theBitArray. | 
| opOpAssign(e2) | Support for operator op= for BitArray. | 
| opOpAssign(b) | Support for operator ~= for BitArray.
 Warning: This will overwrite a bit in the final word
 of the current underlying data regardless of whether it is
 shared between BitArray objects. i.e. D dynamic array
 concatenation semantics are not followed | 
| opOpAssign(nbits) | Operator >>=support. | 
| opOpAssign(nbits) | Operator <<=support. | 
| opSliceAssign(val) | Sets all the values in the BitArrayto the
      value specified byval. | 
| opSliceAssign(val, start, end) | Sets the bits of a slice of BitArraystarting
      at indexstartand ends at index ($D end - 1)
      with the values specified byval. | 
| opUnary() | Support for unary operator ~ for BitArray. | 
| toHash() | Support for hashing for BitArray. | 
| toString(sink, fmt) | Return a string representation of this BitArray. | 
Example
Slicing & bitsSet
import stdExample
Concatenation and appending
import stdExample
Bit flipping
import stdExample
String format of bitarrays
import stdExample
import stdAuthors
Walter Bright, Andrei Alexandrescu, Jonathan M Davis, Alex Rønne Petersen, Damian Ziemba, Amaury SECHET
License
					Copyright © 1999-2024 by the D Language Foundation | Page generated by ddox.