use bitmasking instead of modulo