Can you help me to check a number is even or odd without using any conditions.
arupa
0
Newbie Poster
Recommended Answers
Jump to PostCan't!!
Your question has words "OR" this means you've to use a branched code...
Jump to PostThough zero isn't an even number, it's even enough.
No & 2 == 2 would return false for No = 0.
Modulus wins!Yes, I agree
but you can change the condition likeNo & 1 == 1 means Odd
otherwise Even
All 5 Replies
Ramy Mahrous
401
Postaholic
Featured Poster
selvaganapathy
31
Posting Pro
Alex Edwards
321
Posting Shark
selvaganapathy
31
Posting Pro
Alex Edwards
commented:
Yes, the bitwise AND will always return true when comparing an odd number with 1 since 1 bitAND 1 is true (or 1)
+3
arupa
0
Newbie Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.