another bitwise solution