This is a C# Program to find power of 2 using bitwise operator.
This C# Program Finds Power of 2 using Bitwise Operator.
Here Operations on bits at individual levels can be carried out using Bitwise operations and the whole representation of a number is considered while applying a bitwise operator.
Here is source code of the C# Program to Find Power of 2 using Bitwise Operator. The C# program is successfully compiled and executed with Microsoft Visual Studio. The program output is also shown below.
/* * C# Program to Find Power of 2 using Bitwise Operator */ using System; using System.Collections.Generic; using System.Globalization; using System.Linq; using System.Text; namespace example { internal class Program { private static void Main(string[] args) { int num; Console.Write("Enter a number:"); num = Convert.ToInt32(Console.ReadLine()); bool result = ((num & -num) == num); Console.WriteLine(result); Console.ReadLine(); } } }
In this C# program, we are reading a number using ‘num’ variable. A bitwise operation is used to operations on bits at individual levels. The whole representation of a number is considered while applying a bitwise operator. Print the value of power of 2.
Enter a number:16 True
Sanfoundry Global Education & Learning Series – 1000 C# Programs.
- Get Free Certificate of Merit in C# Programming
- Participate in C# Programming Certification Contest
- Become a Top Ranker in C# Programming
- Take C# Programming Tests
- Chapterwise Practice Tests: Chapter 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
- Chapterwise Mock Tests: Chapter 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
- Practice MCA MCQs
- Apply for C# Internship
- Buy C# Books
- Buy Computer Science Books
- Buy MCA Books