Base.BitVector
— MethodBitVector(x::Unsigned, n::Integer)
Construct a BitVector
of length 0 ≤ n
≤ 128 from an unsigned integer. If n < 8sizeof(x)
, only the first n
bits, numbering from the right, will be preserved; this is equivalent to m = 8sizeof(x) - n; BitVector(x << m >> m, n)
. If n > 8sizeof(x)
, the leading bit positions (reading left to right) are zero-filled analogously to unsigned integer literals.
Examples
julia> B = BitVector(0b101, 4)
4-element BitVector:
1
0
1
0
julia> B == BitVector((true, false, true, false))
true
julia> B == BitVector(0xf5, 4)
true
julia> BitVector(0xff, 0)
0-element BitVector
julia> m = 8sizeof(0xf5) - 3
5
julia> BitVector(0xf5 << m >> m, 3) == BitVector(0xf5, 3)
true
julia> BitVector(0b110, 8sizeof(0b110) - leading_zeros(0b110))
3-element BitVector:
0
1
1
Base.BitVector
— MethodBitVector(x::Unsigned)
Construct a BitVector
of length 8sizeof(x)
from an unsigned integer following the LSB 0 bit numbering scheme (except 1-indexed). Leading bit positions are zero-filled analogously to unsigned integer literals.
Examples
julia> BitVector(0b10010100)
8-element BitVector:
0
0
1
0
1
0
0
1
julia> BitVector(0b10100)
8-element BitVector:
0
0
1
0
1
0
0
0
julia> BitVector(0xff) == trues(8)
true
BitVectorExtensions.lshift!
— Methodlshift!(dest::BitVector, src::BitVector, i::Integer)
Shift the elements of src
left by n
bit positions, filling with false
values, storing the result in dest
. If n < 0
, elements are shifted to the right.
Examples
julia> B = BitVector((false, false, false));
julia> lshift!(B, BitVector((true, true, true,)), 2)
3-element BitVector:
0
0
1
julia> lshift!(B, BitVector((true, true, true,)), -2)
3-element BitVector:
1
0
0
BitVectorExtensions.lshift!
— Methodlshift!(B::BitVector, i::Integer)
Shift the elements of B
left by n
bit positions, filling with false
values. If n < 0
, elements are shifted to the right.
Examples
```jldoctest julia> B = BitVector((true, true, true));
julia> lshift!(B, 2) 3-element BitVector: 0 0 1
julia> lshift!(B, 1) 3-element BitVector: 0 0 0
BitVectorExtensions.lshift
— Methodlshift(B::BitVector, n::Integer)
Return B
with the elements shifted left by n
bit positions, filling with false
values. If n < 0
, elements are shifted to the right.
See also: rshift
Examples
julia> B = BitVector([true, false, true, false, false])
5-element BitVector:
1
0
1
0
0
julia> lshift(B, 1) == B >> 1 # Notice opposite behavior
true
julia> lshift(B, 2)
5-element BitVector:
0
0
1
0
1
BitVectorExtensions.rshift!
— Methodrshift!(dest::BitVector, src::BitVector, i::Integer)
Shift the elements of src
right by n
bit positions, filling with false
values, storing the result in dest
. If n < 0
, elements are shifted to the left.
Examples
julia> B = BitVector((false, false, false));
julia> rshift!(B, BitVector((true, true, true,)), 2)
3-element BitVector:
1
0
0
julia> rshift!(B, BitVector((true, true, true,)), -2)
3-element BitVector:
0
0
1
BitVectorExtensions.rshift!
— Methodrshift!(B::BitVector, i::Integer)
Shift the elements of B
right by n
bit positions, filling with false
values. If n < 0
, elements are shifted to the left.
Examples
julia> B = BitVector((true, true, true));
julia> rshift!(B, 2)
3-element BitVector:
1
0
0
julia> rshift!(B, 1)
3-element BitVector:
0
0
0
BitVectorExtensions.rshift
— Methodrshift(B::BitVector, n::Integer)
Return B
with the elements shifted right by n
bit positions, filling with false
values. If n < 0
, elements are shifted to the left.
Examples
julia> B = BitVector([true, false, true, false, false])
5-element BitVector:
1
0
1
0
0
julia> rshift(B, 1) == B << 1 # Notice opposite behavior
true
julia> rshift(B, 2)
5-element BitVector:
1
0
0
0
0