The most fundamental way to check even/odd
july 2026
What could be the most fundamental way to determine whether a number is even or odd without using the modulo (%) operator? Bits (0/1) the "language of computers," and the only thing a computer TRULY understands.
But how!! how can we determine whether the number is odd or even using just those two digits or some combination of them ?? We will see it gradually...
Basics:
Unary Means - 1
Binary Means - 2 (we are going to deal with this one)
Triplet Means - 3 ....
Definition of Binary System:
even 5yr old knows what a binary system is (the world has changed) :
The binary system is a number or counting system where, Instead of
using ten digits (0–9) like we humans normally do, it uses just two:
0 and 1.
Check out a more formal definition here.
Definition of odd and even :
- A number is said to be even if it is perfectly divisible by 2.
- A number is said to be odd if it is NOT divisible by 2.
Back in the school/college days we were taught that just like decimal number we can perform arithmetic operations on binary numbers as well: we can do addition, subtraction, division, multiplication and so on... Later, in programming, we also learned that binary numbers can be manipulated using bitwise operators,which work on each 0 and 1 separately i.e they operate on thier individual bits. learn more
The table below demonstrates the AND, OR, and XOR bitwise operations.
| Decimal Value | A | B | C | AND | OR | XOR |
|---|---|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| 1 | 0 | 0 | 1 | 0 | 1 | 1 |
| 2 | 0 | 1 | 0 | 0 | 1 | 1 |
| 3 | 0 | 1 | 1 | 1 | 1 | 0 |
| 4 | 1 | 0 | 0 | 0 | 1 | 1 |
| 5 | 1 | 0 | 1 | 0 | 1 | 0 |
| 6 | 1 | 1 | 0 | 0 | 1 | 1 |
Now that we have covered the basic concepts, let's see the implementation.
1] The Decimal/Common Approach:
Steps :
- take input from user .
- divide it by 2
- if its completely divisible by 2 (as said earlier) we return "Even" if its not we return "Odd", as simple as that .
Here is the python program :
what we used here :
- A decimal number (n)
- Modulo Operator (%)
- Divsior (2)
- Comparison Operator (==).
None. just make sure that you dont divide by 0. unless you enjoy crashing programs .
2.1] Binary/fundamental Approach:
Before talking about logic itself , lets understand how it works:
Its all about Observation. look at the image below did you notice
something? Every EVEN number has 0 in the 2⁰ position and for ODD its
1.
| Decimal | Binary | 2⁰ Bit (LSB) | Even/Odd |
|---|---|---|---|
| 0 | 0000 | 0 | Even |
| 1 | 0001 | 1 | Odd |
| 2 | 0010 | 0 | Even |
| 3 | 0011 | 1 | Odd |
| 4 | 0100 | 0 | Even |
| 5 | 0101 | 1 | Odd |
| 6 | 0110 | 0 | Even |
| 7 | 0111 | 1 | Odd |
| 8 | 1000 | 0 | Even |
| 9 | 1001 | 1 | Odd |
I hope By now, you have probably noticed the pattern.
so let's try to program it!!
Steps:
- take a number as input from user .
- convert that number into binary using 'bin()' function in python and store it in variable or don't . it will return string for e.g : 4 will be equals "100"
- compare the last string character with "0"
- if the last character is "0" , function will return "Even" otherwise "Odd".
Here is the program:
what we used here :
- A decimal number (n)
- python's inbuilt function - bin()
- Negative Indexing [-1]
- Comparison Operator (==).
Notice that we are not comparing last character/element with the 0 (integer) ; we are comparing it with "0" (string) if you missed that ... well, more power to you.
2.2] Bitwise AND (&) Approach :
Earlier, we talked about bitwise operators, but Program 2.1 didn't use any of them.Well, That was just one approach. Now let's do it using bitwise AND (&).
Steps:
- First, take a number as input from the user.
- perform a bitwise AND operation between the number and 1 (i.e n & 1).
- If the result is 0, the last bit is 0, which means the number is Even.
- Otherwise, number is Odd asss simple as that.
Here is the program:
Things to notice here :
- We didn't convert the input to binary this time. Why? Because if we did convert it explicitly using the bin() function, it would return something like "0b10101...". If we then tried to convert it into an integer directly, the program will throw an error because the string contains "0b" (It simply indicates that the number is in binary form).
-
Someone: "What if we perform a bitwise operation on a string, for
e.g, "0b0101" & "0001" ?"
We can't, because, as the name suggests, it's a bitwise operator, and it does not work on strings directly. But if you know how to strip a string so that the left part ("0b") and the right part ("0101") get separated, then you can go that way as well by converting "0101" back into an integer .
What we used here :
- A decimal number (n)
- Bitwise AND operator (&)
- Our main character/number (1)
- Comparison operator (==)
I'm Done, here is the summary:
- Even numbers have 0 at their last bit, whereas odd numbers have 1.
- we learnt about three methods for finding out whether the number is even or odd: modulo (%), bin()+Negative_Indexing and bitwise AND (&).
- Out of the three techniques, the bitwise technique (n & 1) seems most straightforward and atomic to ME, rest is up to you.
Dont hesitate to DM me on linkedin.