ellapt

3.5.CheckTheBit

Dec 14th, 2012
31
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. using System;
  2.  
  3. class CheckTheBit
  4. {
  5. static void Main()
  6. {
  7. Console.WriteLine("Find if the bit 3 (counting from 0) of a given integer is 1 or 0.");
  8. Console.WriteLine("Please, enter an integer number: ");
  9. string inputInt = Console.ReadLine();
  10. int checkNum;
  11. int mask3=0x8; // the bit 3 set to 1 is 2pow3=8
  12.  
  13. if (int.TryParse(inputInt, out checkNum))
  14. {
  15. if ((checkNum & mask3) == mask3)
  16. {
  17. Console.WriteLine("The bit 3 of the integer number {0} (HexDec {0:X}) is EQUAL to 1.", checkNum);
  18. }
  19. else
  20. {
  21. Console.WriteLine("The bit 3 of the integer number {0} (HexDec {0:X}) is NOT EQUAL to 1.", checkNum);
  22. }
  23. }
  24. else
  25. {
  26. Console.WriteLine("{0} is not an integer number!", inputInt);
  27. }
  28. }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment