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
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
// create some values var num1 = 3 var num2 = 2 var num3 = 100 var num4 = 20 var num5 = 1 var num6 = 0 // perform OR operation print(num1 | num2) // 3 print(num3 | num4) // 11 print(num5 | num6) // 1
|), we perform a bitwise OR operation on the values we created, then we print the results to the console.
View all Courses