In Swift, performing a bitwise OR operation means adding the binary representation of two decimal values and returning the result in decimal form. We'll need the OR operator |
, which takes two operands. The operands here are the numbers we want to get the sum of their bits.
number1 | number2
number1
and number2
: These are the number values we want to perform the bitwise OR operation on.
The value returned is a decimal representation of the result of adding the bits of number1
and number2
.
// create some valuesvar num1 = 3var num2 = 2var num3 = 100var num4 = 20var num5 = 1var num6 = 0// perform OR operationprint(num1 | num2) // 3print(num3 | num4) // 11print(num5 | num6) // 1
|
), we perform a bitwise OR operation on the values we created, then we print the results to the console.