diff --git a/.zk/notebook.db b/.zk/notebook.db index f5813d8..a679318 100644 Binary files a/.zk/notebook.db and b/.zk/notebook.db differ diff --git a/zk/Bitwise_operators.md b/zk/Bitwise_operators.md index 6f27f06..9064ebe 100644 --- a/zk/Bitwise_operators.md +++ b/zk/Bitwise_operators.md @@ -23,8 +23,43 @@ operators, e.g. `&` instead of `&&`: An example of using the `&` operator: ```py -x =5 +x = 5 y = 3 +a = x & y +b = x | y ``` +The value of `a` will be 1. The reason is we are looking at the bit values of +`x` and `y` and then applying Boolean AND to each bit: + +``` +x = 5 = 0101 +y = 3 = 0011 +a = 1 = 0001 +``` + +Working from right to left for each column: + +- true and true = true +- false and true = false +- true and false = false +- false and false = false + +This leaves us with 0001 which is equal to 1 in binary and denary. + +For the case of bitwise OR we get 7 as the result of `x | y`: + +``` +x = 5 = 0101 +y = 3 = 0011 +b = 7 = 0111 +``` + +- true or true = true +- false or true = true +- true or false = true +- false or false = true + +This leaves us with 0111 which is equal to 7 in denary. + ## Related notes