# Why is the negation of a Boolean array a BitArray

**URL:** https://discourse.julialang.org/t/why-is-the-negation-of-a-boolean-array-a-bitarray/29211
**Category:** General Usage
**Created:** [September 26, 2019, 10:58pm UTC](https://discourse.julialang.org/t/why-is-the-negation-of-a-boolean-array-a-bitarray/29211 "2019-09-26T22:58:58Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![SEA](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sea/32/8956_2.png) [@SEA](https://discourse.julialang.org/u/SEA)
#### Post date: [September 26, 2019, 10:58pm UTC](https://discourse.julialang.org/t/why-is-the-negation-of-a-boolean-array-a-bitarray/29211/1 "2019-09-26T22:58:59Z")

</div>

If b = rand(Bool, 3)

then all of

1. .!b
2. .~b
3. xor.(true, b)

return a BitArray{1} type. Given that the input types are always Array{Bool, 1}, I find that curious. Is this behavior wanted, and if so, why?

---

<div class="post-metadata">

### Author: ![sairus7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sairus7/32/10816_2.png) [@sairus7](https://discourse.julialang.org/u/sairus7)
#### Post date: [September 26, 2019, 11:40pm UTC](https://discourse.julialang.org/t/why-is-the-negation-of-a-boolean-array-a-bitarray/29211/2 "2019-09-26T23:40:36Z")

</div>

Smaller memory size and faster vectorized bit-wise operations?  
See also: [Arrays · The Julia Language](https://docs.julialang.org/en/v1/base/arrays/#Base.BitArray)

---

<div class="post-metadata">

### Author: ![SEA](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sea/32/8956_2.png) [@SEA](https://discourse.julialang.org/u/SEA)
#### Post date: [September 27, 2019, 5:51pm UTC](https://discourse.julialang.org/t/why-is-the-negation-of-a-boolean-array-a-bitarray/29211/3 "2019-09-27T17:51:52Z")

</div>

That makes sense. Wouldn’t it then be more consistent to have rand(Bool, 3) return a BitArray too? I just find it surprising that these functions do not preserve the type.

---

<div class="post-metadata">

### Author: ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)
#### Post date: [September 28, 2019, 4:44am UTC](https://discourse.julialang.org/t/why-is-the-negation-of-a-boolean-array-a-bitarray/29211/4 "2019-09-28T04:44:56Z")

</div>

> [@SEA](#):
>
> Wouldn’t it then be more consistent to have rand(Bool, 3) return a BitArray too?

No, it would be _inconsistent_, as `rand(T, n)` gives `Vector{T}`s. See `bitrand`.
