# Bitwise or

**URL:** <https://discourse.julialang.org/t/bitwise-or/84732>\
**Category:** General Usage\
**Tags:** question\
**Created:** [July 25, 2022, 7:16am UTC](https://discourse.julialang.org/t/bitwise-or/84732 "2022-07-25T07:16:51Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ellocco](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ellocco/32/31331_2.png) [@ellocco](https://discourse.julialang.org/u/ellocco)\
**Post date:** [July 25, 2022, 7:16am UTC](https://discourse.julialang.org/t/bitwise-or/84732/1 "2022-07-25T07:16:51Z")

</div>

I would like to figure out, if the value of a variable is either one or two.  
The strange thing is that the result of `x == 1` is of type `Bool`, but `bitwise or, "|"` makes a difference between `(x == 1)` and `x == 1`, is this an expected behaviour?

```julia
x = 1
x == 1 | x == 2 # result false
(x == 1) | (x == 2) # result true
b = x == 1 # b is of type "Bool"
println(typeof(b))

```

---

<div class="post-metadata">

**Author:** ![Sukera](https://avatars.discourse-cdn.com/v4/letter/s/ce7236/32.png) [@Sukera](https://discourse.julialang.org/u/Sukera)\
**Post date:** [July 25, 2022, 7:21am UTC](https://discourse.julialang.org/t/bitwise-or/84732/2 "2022-07-25T07:21:23Z")

</div>

Yes, this is expected. `|` has higher precedence than `==`, which means your second example is parsed as if it were written like `(x == (1 | x) == 2)`.

See also

[https://docs.julialang.org/en/v1/manual/mathematical-operations/#Operator-Precedence-and-Associativity](https://docs.julialang.org/en/v1/manual/mathematical-operations/#Operator-Precedence-and-Associativity)

Additionally, `==` between integers and booleans is well defined, since `true == 1` and `false == 0`.

---

<div class="post-metadata">

**Author:** ![Benny](https://avatars.discourse-cdn.com/v4/letter/b/49beb7/32.png) [@Benny](https://discourse.julialang.org/u/Benny)\
**Post date:** [July 25, 2022, 7:24am UTC](https://discourse.julialang.org/t/bitwise-or/84732/3 "2022-07-25T07:24:32Z")

</div>

Quick way to see the precedence:

```julia
julia> Meta.@lower x == 1 | x == 2
:($(Expr(:thunk, CodeInfo(
    @ none within `top-level scope`
1 ─ %1 = 1 | x
│ %2 = x == %1
└── goto #3 if not %2
2 ─ %4 = %1 == 2
└── return %4
3 ─ return false
))))

```

---

<div class="post-metadata">

**Author:** ![ellocco](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ellocco/32/31331_2.png) [@ellocco](https://discourse.julialang.org/u/ellocco)\
**Post date:** [July 25, 2022, 7:44am UTC](https://discourse.julialang.org/t/bitwise-or/84732/4 "2022-07-25T07:44:45Z")

</div>

> [@Benny](#):
>
> `Meta.@lower x == 1 | x == 2`

Thanks both for your explanations!!! 🙂
