# Does Julia has bitwise circular shift?

**URL:** <https://discourse.julialang.org/t/does-julia-has-bitwise-circular-shift/44220>\
**Category:** General Usage\
**Created:** [August 3, 2020, 10:07pm UTC](https://discourse.julialang.org/t/does-julia-has-bitwise-circular-shift/44220 "2020-08-03T22:07:16Z")\
**Posts on this page:** 1\
**Showing post:** 2

<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:** [August 3, 2020, 10:21pm UTC](https://discourse.julialang.org/t/does-julia-has-bitwise-circular-shift/44220/2 "2020-08-03T22:21:52Z")

</div>

I don’t think it exists, but for `Int64` this should work and be about 3x slower than other bitshifts (since it uses 3 of them). You could easily enough write methods for other types of `Integer`, but I don’t know of a way in Julia to automatically get the number of bits in an integer.

```julia
function circshift(x, n)
    return (x<<n) | (x>>(muladd(8, sizeof(x), -n)
end

```

EDIT: now should work for any `Integer` subtype

---

_[View the full topic](https://discourse.julialang.org/t/does-julia-has-bitwise-circular-shift/44220)._
