How to check odd or even using bitwise operator in C

1 Answer

0 votes
#include <stdio.h>

int main()
{
    unsigned int num = 28; // 00011100

	if (num & 1 == 1)
		printf("Odd");
	else
		printf("Even");

    return 0;
}

  
  
  
/*
run:
  
Even
  
*/


answered May 10, 2015 by avibootz
edited Dec 21, 2023 by avibootz

Related questions

1 answer 204 views
1 answer 238 views
1 answer 279 views
2 answers 285 views
2 answers 274 views
1 answer 243 views
...