Contents
Masking
mask
BitsX.Bits.mask — Functionmask([T=UInt], i::Integer)
mask([T=UInt], r::UnitRange)
mask([T=UInt], itr)Return n::T with the specified bits set to one and the rest zero. The bits specified by each item in itr will be set to one. Overlaps between ranges will have their bits set to one.
See leftmask, rightmask, rangemask.
Examples
julia> bitstring(mask(UInt8, 3))
"00000100"
julia> bitstring(mask(UInt8, (1, 5, 8)))
"10010001"
julia> bitstring(mask(UInt8, (2, 5, 8)))
"10010010"
julia> bitstring(mask(1:2:64))
"0101010101010101010101010101010101010101010101010101010101010101"
julia> bitstring(mask(UInt16, (1:3, 9, 14:16)))
"1110000100000111"masked
BitsX.Bits.masked — Functionmasked([ib::IndexBase], x::T, inds...) where {T}Return the result of applying the mask determined by inds to x.
That is, return x & mask(T, inds...)
Examples
julia> masked(0b11110011, 1:5) === 0b00010011
true
julia> x = rand(); masked(-x, 1:63) === x
truerightmask
BitsX.Bits.rightmask — Functionrightmask([T=UInt], i)Return n::T such that the ith bit and all bits to the right (lower) are one, and all bits to the left of the ith bit (higher) are zero.
See also leftmask, rangemask, mask.
Examples
julia> bitstring(rightmask(UInt8, 3))
"00000111"leftmask
BitsX.Bits.leftmask — Functionleftmask([T=UInt], i)Return n::T such that the ith bit and all bits to the left (higher) are one, and all bits to the right of the ith bit (lower) are zero.
See rightmask, rangemask, mask.
Examples
julia> bitstring(leftmask(UInt8, 3))
"11111100"rangemask
BitsX.Bits.rangemask — Functionrangemask([T=UInt], ilo, ihi)
rangemask([T=UInt], (ilo, ihi)...)Return n::T such that all bits in the range ilo to ihi, inclusive, are one, and all other bits are zero. If Tuples (ilo, ihi)... are given, then set bits in each range to one.
See leftmask, rightmask, mask.
Examples
julia> bitstring(rangemask(UInt8, 2, 7))
"01111110"
julia> bitstring(rangemask(UInt16, (1, 3), (5, 8), (14, 16)))
"1110000011110111"
julia> bitstring(rangemask(UInt8, (1, 5), (4, 8)))
"11111111"Miscellany
undigits
BitsX.Bits.undigits — Functionundigits([IntT=Int], A; base=10, rev=false)::IntTThe inverse of digits. That is undigits(digits(n; base); base) == n. The number returned is of type IntT provided that the type is stable under + and *, and that each element of A can be converted to IntT.
Exceptions
OverflowErrorifArepresents a number larger thantypemax(IntT). ForUnsignedtypes the check is more strict in thatlength(A)must not be greater than the number of bits inIntT, even if there are leading zeros.
Examples
julia> undigits([2, 4])
42
julia> undigits([2, 4]; rev=true)
24julia> undigits(UInt8, [1, 0, 1, 1]; base=2) 0x0d
julia> bstring(undigits(UInt8, [1, 0, 1, 1]; base=2); pad=true) "1011"
bitcollect
BitsX.Bits.bitcollect — Functionbitcollect(obj)Convert the representation of a bit array obj to an Array{Bool}.
bit_count_ones
BitsX.Bits.bit_count_ones — Functionbit_count_ones(v)Count the number of bit values in v equal to one.
bit_count_ones(s::AbstractString)Count the number of characters in s equal to '1'.
bit_count_zeros
BitsX.Bits.bit_count_zeros — Functionbit_count_zeros(v)Count the number of bit values in v equal to one.
bit_count_zeros(s::AbstractString)Count the number of characters in s equal to '0'.
BitStringArray
BitStringArray has essential things implemented. Documentation is incomplete.
BitsX.Bits.BitStringArray — TypeBitStringArray{T <: AbstractVector{<:AbstractString}, N} <: AbstractArray{Bool, N}
An array of Bools represented by a vector of bitstrings.