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 217 views
1 answer 241 views
1 answer 285 views
2 answers 297 views
2 answers 282 views
1 answer 253 views
...