Finds the bitwise ‘OR’ value of two numbers and returns it.
BITOR(numberOne, numberTwo)
numberOne and numberTwo must be a decimal and should be 0 or higher.
Example:
If numberOne contains 1 and numberTwo contains 2:
BITOR(1, 2)
returns 3
numberOne:
numberTwo:
Result:
The BITOR (or bitwise OR) function is a logical operation that compares two numbers at the binary level. For each corresponding bit, if either of the bits is a 1, the resulting bit is a 1. If both bits are 0, the result is 0.
A common application of the BITOR function is in computer networking, specifically for setting and managing permissions or flags. Let's consider a scenario where you are managing user permissions for a network-attached storage (NAS) device.
Each permission can be represented by a unique power of 2, also known as a bit flag. This is because in binary, each power of 2 occupies a unique bit position.
Permission | Decimal Value | Binary Representation | ||
|---|---|---|---|---|
A | B | C | ||
1 | Read | 1 | 0001 | |
2 | Write | 2 | 0010 | |
3 | Execute | 4 | 0100 | |
4 | Delete | 8 | 1000 |
Now, let's say we have three users and we want to grant them different combinations of permissions. We can use the BITOR function to combine these permissions into a single number.
User | Permissions Granted | BITOR Calculation | Decimal Value | ||
|---|---|---|---|---|---|
A | B | C | D | ||
1 | Alice | Read, Write | BITOR(1, 2) | 3 | |
2 | Bob | Read, Execute | BITOR(1, 4) | 5 | |
3 | Charlie | Read, Write, Delete | BITOR(BITOR(1, 2), 8) | 11 |
This method is incredibly efficient for storing and checking permissions. A single number (e.g., 3, 5, or 11) represents a complex set of permissions. To check if a user has a specific permission, a programmer can use a bitwise AND operation. For example, to check if Charlie has "Delete" permission, you would perform BITAND(11, 8), which would result in 8, proving the permission exists. If a user did not have the permission, the result would be 0. This is a very fast and space-efficient way to manage multiple binary flags in computing.
PRODUCT & FEATURES
RESOURCES
Terms | Privacy | Spam Policy
© 2026 Zapof