@gorokhovsky Oh my, I haven't realized at all that it doesn't matter whether the highest-differing bit is zero or one in the mask because it's zero anyway in
m. That certainly simplifies the solution!
I've been coding ever since before I was 13 years old. I had no PC, so I would write code on a piece of paper and then execute it in my mind. I work now for Russian Mission Control Center (dealing mainly with International Space Station telemetry), which is fun except that it's in Russia (not my kind of country, as I tend to respect laws and like quiet life). My hobbies are quantum mechanics and foreign languages, but I hardly devote any time to them because most of the time I either code or learn to code better. My dream is to leave Russia for good and live and work for a nice Western company in a nice Western country, but it remains just a dream for now.