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 0This example uses
bitbroadcastto apply thexorfunction element-wise over twoBitArrays. -
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 0Here,
bitbroadcastis used to perform a bitwisebitandoperation between aBitArrayand 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 1This example demonstrates the use of
bitbroadcastto 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 BitArrays 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.