Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- class WitchBitStayOfPositionP
- {
- static void Main()
- {
- Console.Write("Enter Number here: n = ");
- int n = Convert.ToInt32(Console.ReadLine());
- Console.Write("Enter Position here: p = ");
- int p = Convert.ToInt32(Console.ReadLine());
- /* Counting random number, witch in binary representation has a bit 1 of position p and
- the other bits are 0 . Example: p = 5 position(binary) = 100000 and position(decimal) = 32 */
- int position = Convert.ToInt32(Math.Pow(2, p));
- /* Example: n = 35 (100011); p = 5; position = 32 (100000) , 1&1 == 1 => bit 1 */
- if ((n & position) == 0)
- {
- Console.WriteLine("The bit, witch stay ot position P from number N is: \n0");
- }
- else
- {
- Console.WriteLine("The bit, witch stay ot position P from number N is: \n1");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement