quote:Original post by peter86Here you have the truth table for OR:
Could someone please give some examples and compare them with a logical or so I can see the diffrence?
0 0 = 0 (false)
0 1 = 1 (true)
1 0 = 1 (true)
1 1 = 1 (true)
If you have one bit, it is either 0 (false) or 1 (true). When you OR two values, you apply that truth table on them to calculate the result, which is either 0 (true) or 1 (false).
When doing a logical OR operation (i | j), both value are evaluated to either true (if non-zero) or false (if zero), and the operation is applied to those. That is, if both values are zero, the result is false, and in all other cases true.
When you do a bitwise OR operation (i || j), you perform that calculatation on each bit of the two values at the same position, and store the result in a third value at the same position. Here we do a bitwise or on two 8-bit values:
11010001 (= 209)OR 01110110 (= 118)===========-------- 11110111 (= 247)or for easier comparison with the table above:1 0 = 11 1 = 10 1 = 11 1 = 10 0 = 00 1 = 10 1 = 11 0 = 1
I hope we''re getting somewhere. Otherwise, you should go out and find a book (or, failing that, a web page)about binary logic.