Venciity

BitWiseOperators - проверка на бит

Jan 30th, 2014
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.75 KB | None | 0 0
  1. /*Декларирайте променлива от тип byte и я инициализирайте с произволна стойност.
  2.  * Отпечатайте на екрана "access granted", ако 4-тия бит (позициите започват от 0) е 1
  3.  * или "access denied" ако 4-тия бит е 0    */
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9.  
  10. namespace ex6
  11. {
  12.     class Program
  13.     {
  14.         static void Main(string[] args)
  15.         {
  16.             byte n = 56;            //00111000
  17.             int bit4 = 1 << 4;      //00010000
  18.             Console.WriteLine((n & bit4) == bit4 ? "access granted" : "access denied");
  19.         }
  20.     }
  21. }
Advertisement
Add Comment
Please, Sign In to add comment