Each bit position represents whether that length is valid.
For example, if lengths 7, 8, 9 are valid:
Bit 7 = 1, Bit 8 = 1, Bit 9 = 1
Binary: 0b1110000000 = 896
To check if a length is valid: (bitmap & (1 << length)) !== 0
To get min length: Math.clz32(bitmap) related calculation
To get max length: 31 - Math.clz32(bitmap)
This is more efficient than arrays for membership checks (O(1) vs O(n))
and more compact in memory.
Bitmap representing valid phone number lengths.
Each bit position represents whether that length is valid. For example, if lengths 7, 8, 9 are valid:
To check if a length is valid:
(bitmap & (1 << length)) !== 0To get min length:Math.clz32(bitmap)related calculation To get max length:31 - Math.clz32(bitmap)This is more efficient than arrays for membership checks (O(1) vs O(n)) and more compact in memory.