Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- class CheckTheThirdBit
- {
- static void Main()
- {
- int number, checkNumber;
- Console.Write("Enter a number: ");
- if (int.TryParse(Console.ReadLine(), out number) && number >= int.MinValue && number <= int.MaxValue)
- {
- checkNumber = number & 8;
- bool thirdBitValue = checkNumber != 0;
- if (thirdBitValue)
- {
- Console.WriteLine("The bit 3 of {0} is 1.\n", number);
- Main();
- }
- else
- {
- Console.WriteLine("The bit 3 of {0} is 0\n", number);
- Main();
- }
- }
- else
- {
- Console.WriteLine("Invalid input! Please enter a number between {0} and {1}", int.MinValue, int.MaxValue);
- Main();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment