bitwise solution