How to Check Even or Odd Number using Bitwise Operator in C# ?

Do you want to find if the number is odd or even in C# ? , using Bitwise AND operator is one of the easiest way to find it.

How to Check Even or Odd Number using Bitwise Operator in C# ?

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Ginktage
{
    internal class Program
    {
        private static void Main(string[] args)
        {
            int num = 11;
            bool value = IsEvenNumber(num);
            Console.WriteLine(value);
            Console.ReadLine();
        }
        // Function to Check if the Number is Odd or Even using Bitwise Operator.
        public static bool IsEvenNumber(int num)
        {
            bool value = ((num & 1) == 0);
            return value;
        }    
    }
    
}
If you enjoyed this post, please consider leaving a comment or subscribing to the RSS feed to have future articles delivered to your feed reader.

Leave a Reply