wingman007

BitPosition

Sep 15th, 2025
417
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.37 KB | Software | 0 0
  1. class BitPosition
  2. {
  3.     static void Main() {
  4.         Console.Write("Input a number n:");
  5.         int number = int.Parse(Console.ReadLine());
  6.  
  7.         Console.WriteLine("Input position p(0 the right bit):");
  8.         int p = int.Parse(Console.ReadLine());
  9.  
  10.         int bit = (number >> p) & 1;
  11.  
  12.         Console.WriteLine($"On posion {p} we have: {bit}");
  13.     }
  14. }
  15.  
Tags: BitPosition
Advertisement