so the bitwise stuff turned out to be, surprisingly!, harder than I thought