Contents

Masking

mask

BitsX.Bits.maskFunction
mask([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"
source

masked

BitsX.Bits.maskedFunction
masked([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
true
source

rightmask

BitsX.Bits.rightmaskFunction
rightmask([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"
source

leftmask

BitsX.Bits.leftmaskFunction
leftmask([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"
source

rangemask

BitsX.Bits.rangemaskFunction
rangemask([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"
source

Miscellany

undigits

BitsX.Bits.undigitsFunction
undigits([IntT=Int], A; base=10, rev=false)::IntT

The 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

  • OverflowError if A represents a number larger than typemax(IntT). For Unsigned types the check is more strict in that length(A) must not be greater than the number of bits in IntT, even if there are leading zeros.

Examples

julia> undigits([2, 4])
42

julia> undigits([2, 4]; rev=true)
24

julia> undigits(UInt8, [1, 0, 1, 1]; base=2) 0x0d

julia> bstring(undigits(UInt8, [1, 0, 1, 1]; base=2); pad=true) "1011"

source

bitcollect

bit_count_ones

BitsX.Bits.bit_count_onesFunction
bit_count_ones(v)

Count the number of bit values in v equal to one.

source
bit_count_ones(s::AbstractString)

Count the number of characters in s equal to '1'.

source

bit_count_zeros

BitsX.Bits.bit_count_zerosFunction
bit_count_zeros(v)

Count the number of bit values in v equal to one.

source
bit_count_zeros(s::AbstractString)

Count the number of characters in s equal to '0'.

source

BitStringArray

BitStringArray has essential things implemented. Documentation is incomplete.

BitsX.Bits.BitStringArrayType

BitStringArray{T <: AbstractVector{<:AbstractString}, N} <: AbstractArray{Bool, N}

An array of Bools represented by a vector of bitstrings.

source