Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Write an expression that extracts from given integer n the value of given bit at index p.
- namespace _12.ExtractBitFromIntegerOnGivenPosition
- {
- using System;
- public class ExtractBitFromIntegerOnGivenPosition
- {
- public static void Main(string[] args)
- {
- checked
- {
- Console.Write("Enter a whole non-negative number: ");
- uint num = uint.Parse(Console.ReadLine());
- int indexP;
- do
- {
- Console.Write("Enter index for Bit position: ");
- }
- while (!int.TryParse(Console.ReadLine(), out indexP) || indexP < 0 || indexP > 31);
- uint bitValueOnPositionP = (num >> indexP) & 1;
- Console.WriteLine("In Given number, on position {0}, Bit Value is: {1} !", indexP, bitValueOnPositionP);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement