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;
        }    
    }
    
}

Leave A Reply

Your email address will not be published. Required fields are marked *

You May Also Like

This C# program calculates and displays an upper triangular matrix based on user input. Problem Statement: The program takes the...
This C# program serves as a demonstration of bitwise operators, which are fundamental operators used for manipulating individual bits in...
This C# program is designed to interchange or swap the columns of a matrix. A matrix is a two-dimensional array...