Bit functions
Usage:
bitAnd(a, b)
bitAnd
returns the bitwise AND of expressions a
and b
.
Examples:
-- perform 0b1 & 0b11bitAnd(1, 3)-- extract the least significant bit of the integer value of double1bitAnd(toUInt8(double1), 1)
Usage:
bitCount(a)
bitCount
returns the number of bits set to one in the binary representation of a
.
Examples:
-- get the number of 1 bits in the binary representation of the float `double1`bitCount(double1)-- get the number of 1 bits in the binary representation of `double1` as an integerbitCount(toUInt32(double1))-- select rows where at least 5 bits are 1SELECT * WHERE bitCount(double1) > 5
Usage:
bitHammingDistance(x, y)
bitHammingDistance
returns the number of bits that differ between x
and y
.
Examples:
-- returns zerobitHammingDistance(1, 1)-- returns 2bitHammingDistance(3, 0)
Usage:
bitNot(a)
bitNot
returns a
with all bits flipped.
Examples:
bitNot(1)
Usage:
bitOr(a, b)
bitOr
returns the inclusive bitwise or of a
and b
.
Examples:
-- returns 3bitOr(1, 2)
Usage:
bitRotateLeft(a, n)
bitRotateLeft
rotates all bits in a
left by n
positions.
Examples:
-- returns 2bitRotateLeft(1, 1)-- returns 1bitRotateLeft(128, 1)
Usage:
bitRotateRight(a, n)
bitRotateRight
rotates all bits in a
right by n
positions.
Examples:
-- returns 128bitRotateRight(1, 1)-- returns 3bitRotateRight(12, 2)
Usage:
bitShiftLeft(a, n)
bitShiftLeft
shifts all bits in a
left by n
positions.
Examples:
-- returns 2bitShiftLeft(1, 1)-- returns 0bitShiftLeft(128, 1)
Usage:
bitShiftRight(a, n)
bitShiftRight
shifts all bits in a
right by n
positions.
Examples:
-- returns 0bitShiftRight(1, 1)-- returns 3bitShiftRight(12, 2)
Usage:
bitTest(a, n)
bitTest
returns the value of bit n
in number a
.
Examples:
-- returns 1bitTest(3, 1)-- return 0bitTest(2, 1)-- select rows where a particular bit is 1SELECT * WHERE bitTest(double1, 2)
Usage:
bitXor(a, b)
bitXor
returns the bitwise exclusive-or of a
and b
.
Examples:
-- returns 3bitXor(1, 2)-- returns 0bitXor(3, 3)
Was this helpful?
- Resources
- API
- New to Cloudflare?
- Directory
- Sponsorships
- Open Source
- Support
- Help Center
- System Status
- Compliance
- GDPR
- Company
- cloudflare.com
- Our team
- Careers
- © 2025 Cloudflare, Inc.
- Privacy Policy
- Terms of Use
- Report Security Issues
- Trademark
-