What is the output of this code?
Please help me understand why this is 7? I've tested this code using different numbers and I still can't figure out the logic...
If you also thought this was hard to understand please EDIT: DO NOT give my question a like as asking for such things will create negativity in a rather positive community environment...
i dont understand why the hostilaty. This was a question in a challenge that both of us got wrong. I tries googling it and tried using the code editor and still dont understand. any help would be very appreciates
Mr. listen. "Mr." i googled and did research for 10-15 minutes. please, do tell me what exactly you would "google" to figure out that "print (5|3)" had anything to do with bitwise... your answer was unhelpful and condicending.
The | operator is called as the BITWISE OR operator.
0 OR 0 = 0
0 OR 1 = 1
1 OR 0 = 1
1 OR 1 = 1
Here's how it works:
5 = 00000101 (8 bit binary value of 5)
3 = 00000011 (8 bit binary value of 3)
5|3 = 00000111 = 7 (in decimal)
Every bit of the two numbers are operated with | (OR) operator.
Muhammad Arbi I recommend just focusing on the python course that you have already started itself. There is enough there to learn, just keep in mind that bitwise operators exists and can executed in python scripts. Keep it up, this is a good place to start
For to understanding you must to learning a struct of byte in binary system.
The number 5 in binary is 00000101
And number 3 in binary is 00000011
Logical | using to binary number
The result of | is. 00000111
This is the number 7