Advertisement
Vladimir76

задача 13

Dec 29th, 2013
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.35 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace zad_13
  7. {
  8.     class zad13
  9.     {
  10.         static void Main(string[] args)
  11.         {
  12.             Console.Write("Enter the nomber  - n : ");
  13.             long n = long.Parse(Console.ReadLine());
  14.  
  15.             if ((n >= Int32.MinValue) && (n <= Int32.MaxValue))
  16.             {
  17.  
  18.                 Console.Write("Enter the position  - p : ");
  19.                 int p = int.Parse(Console.ReadLine());
  20.  
  21.                 if ((p >= 0) && (p <= 31))
  22.                 {
  23.  
  24.                     long n1 = n & (1 << p);
  25.  
  26.                     if (n1 == 0)
  27.                     {
  28.                         n = n | (1 << p);
  29.                         Console.WriteLine("New nomber -n = " + n);
  30.                     }
  31.                     else
  32.                     {
  33.                         n = n ^ (1 << p);
  34.                         Console.WriteLine("New nomber -n = " + n);
  35.                     }
  36.                 }
  37.                 else
  38.                 {
  39.                     Console.WriteLine("Enter a value in the range:" + "0" + "...." + "31");
  40.                 }
  41.             }
  42.             else
  43.             {
  44.                 Console.WriteLine("Enter a value in the range : " + Int32.MinValue + "...." + Int32.MaxValue);
  45.             }
  46.            
  47.            
  48.         }
  49.     }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement