Does Julia has bitwise circular shift?

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.

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

EDIT: now should work for any Integer subtype

1 Like