Know if number is odd or even without using the modulus operator? | Sololearn: Learn to code for FREE!
Nouvelle formation ! Tous les codeurs devraient apprendre l'IA générative !
Essayez une leçon gratuite
0

Know if number is odd or even without using the modulus operator?

I have an int a = 17; I want to know if the nunber is odd or even WITHOUT the modulus operator.

3rd Jul 2016, 1:01 AM
Garme Kain
Garme Kain - avatar
2 Réponses
+ 1
int b =a÷2 if b×2==a a is even else a is odd
3rd Jul 2016, 10:23 AM
mali Schwartz
mali Schwartz - avatar
+ 1
bool isOdd = a & 1;
3rd Jul 2016, 11:19 AM
Garme Kain
Garme Kain - avatar