WojciechMula / toys

Storage for my snippets, toy programs, etc.
BSD 2-Clause "Simplified" License
316 stars 38 forks source link

all-higher-set can be simplified #12

Closed falk-hueffner closed 4 years ago

falk-hueffner commented 4 years ago

in bit-twiddling/all-higher-set.c, the function can be simplified:

int is_pattern(uint16_t x) {
    const uint16_t n = -x;
    return (n ^ x) < x;
}
WojciechMula commented 4 years ago

Thanks a lot! Will update soon. :)

WojciechMula commented 4 years ago

Finally added. That's really clever, like it very much.