# C Program#160 – To check whether a number is even or odd using bit-wise operator.

##### Program to check whether a number is even or odd using bit-wise operator.:

**Program Logic : **

**Even**number’s**Least Significant Bit (LSB)**is always**OFF(0)**.such as –**2**(001**0**),**4**( 010**0**),**6**(011**0**),**8**(100**0**), 98 (0110 001**0**)- Thus,
**Bitwise AND**operation by**1**with**EVEN**, always results in**Zero (0)**using number & 1 . **Odd**number’s**Least Significant Bit (LSB)**is always**ON(1)**.such as –**3**(001**1**),**5**( 010**1**),**7**(011**1**),**9**(100**1**),**99**(0110 001**1**)- Thus,
**Bitwise AND**operation by**1**with**ODD**, always results in**ONE(1)**using number & 1 . - So it concludes to – if ( (number & 1)==1 ) its
**ODD**, otherwise**EVEN**. - Still not understood ? See the
**proper working example**in action below.

**Full Well Commented, Self-Explanatory Example Program of the same given below.**

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
/*C Program#160 - To check whether a number is even or odd using bitwise operator. Least Significant Bit for 1. Even Number = 0 (LSB)( EVENNUMBER & 1 = 0 Always) 2. Odd Number = 1 (LSB) ( ODDNUMBER & 1 = 1 Always) |Source : www.kshitijdivakar.com | Editor : Code::Blocks 16.01 mingW (Windows)*/ #include<stdio.h> int main() { int number; printf("\n\n Enter Number : "); scanf("%d",&number); if(number & 1 == 1) { printf("\n\n Result : %d is an ODD number.",number); } else { printf("\n\n Result : %d is an EVEN number.",number); } printf("\n\n"); return 0; } |

**Below Here are Two Output of the program.**

**Output of the Program (Run 1 ) : Input : ODD number.:**

**Output of the Program (Run 2 ) : Input : EVEN number.:**