# How to do xor(all bits from an Integer) efficiently?

**URL:** <https://discourse.julialang.org/t/how-to-do-xor-all-bits-from-an-integer-efficiently/98338>\
**Category:** General Usage\
**Created:** [May 4, 2023, 6:34pm UTC](https://discourse.julialang.org/t/how-to-do-xor-all-bits-from-an-integer-efficiently/98338 "2023-05-04T18:34:48Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![putianyi888](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/putianyi888/32/32279_2.png) [@putianyi888](https://discourse.julialang.org/u/putianyi888)\
**Post date:** [May 4, 2023, 6:34pm UTC](https://discourse.julialang.org/t/how-to-do-xor-all-bits-from-an-integer-efficiently/98338/1 "2023-05-04T18:34:48Z")

</div>

For example, I want a function `fun` such that `fun(0b0101) = xor(false, true, false, true)`

A solution for Int64 would be sufficient. Solutions for short integers are more welcome.

---

<div class="post-metadata">

**Author:** ![Oscar\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oscar_smith/32/25343_2.png) [@Oscar\_Smith](https://discourse.julialang.org/u/Oscar_Smith)\
**Post date:** [May 4, 2023, 6:35pm UTC](https://discourse.julialang.org/t/how-to-do-xor-all-bits-from-an-integer-efficiently/98338/2 "2023-05-04T18:35:47Z")

</div>

`f(x)=isodd(count_ones(x))`
