bitbroadcast
bitbroadcast(f, As...)
Like broadcast
, but allocates a BitArray
to store the result, rather then an Array
.
Examples
-
Broadcast a function over multiple bit arrays:
julia> bitbroadcast.(xor, BitArray([1, 0, 1, 0]), BitArray([0, 1, 1, 0])) 4-element BitArray{1}: 1 1 0 0
This example uses
bitbroadcast
to apply thexor
function element-wise over twoBitArray
s. -
Broadcast a function over a bit array and other arguments:
julia> bitbroadcast.(bitand, BitArray([1, 1, 0, 0]), 0b1100) 4-element BitArray{1}: 0 0 0 0
Here,
bitbroadcast
is used to perform a bitwisebitand
operation between aBitArray
and an integer value. - Apply a function to a single bit array:
julia> bitbroadcast.(~, BitArray([1, 0, 1, 0])) 4-element BitArray{1}: 0 1 0 1
This example demonstrates the use of
bitbroadcast
to apply the bitwise negation (~
) function to a singleBitArray
.
Common mistake example:
julia> bitbroadcast.(+, BitArray([1, 0, 1]), BitArray([0, 1]))
ERROR: DimensionMismatch("arrays could not be broadcast to a common size")
In this example, the two BitArray
s being broadcasted have different sizes, resulting in a DimensionMismatch
error. Make sure that the dimensions of the input arrays are compatible for broadcasting with bitbroadcast
.
See Also
User Contributed Notes
Add a Note
The format of note supported is markdown, use triple backtick to start and end a code block.