Bit twiddling for checking whether a number is in particular range

前端 未结 3 2208
甜味超标
甜味超标 2021-02-19 20:16

I found some interesting bit twiddling in \"source\\common\\unicode\\utf.h\" file of ICU library (International Components for Unicode). The bit twiddling is intend

3条回答
  •  天涯浪人
    2021-02-19 20:39

    The formula works whenever the range you are looking for starts at a multiple of a power of 2 (that is, 1 or more bits at the low end of the binary form of the number ends in 0) and the size of the range is 2^n-1 (that is, low&high == low and low|high == high).

提交回复
热议问题