write code to determine if the 3rd and 22nd bits starting fr

write code to determine if the 3rd and 22nd bits starting from the right of an interger are set

Solution

Hi, Please find my Java progrma.

You have not mentioned about Progrmming language.

Please let me know in case of any issue.

public class Test {

  

   public static void is3rdAnd22ndDigitsSet(int n){

      

       System.out.println(n +\" in binary: \"+Integer.toBinaryString(n));

       int x = 1; // 00000000 00000000 00000000 00000001

       x = x<<2; // shifting 2 bits left : 00000000 00000000 00000000 00000100

      

       int y = 1; //00000000 00000000 00000000 00000001

       y = y<<21; // 00000000 01000000 00000000 00000000

      

       // if (n & y) != 0 and (n & x) != 0 then , 3rd and 22nd digits of n are set

       if((y & n) != 0 && (x & n) !=0)

           System.out.println(\"3rd and 22nd digits of n are set\");

       else

           System.out.println(\"3rd and 22nd digits of n are NOT set\");

      

   }

   public static void main(String[] args) {

       is3rdAnd22ndDigitsSet(54567);

   }

}

/*

Sample run:

54567 in binary: 1101010100100111

3rd and 22nd digits of n are NOT set

*/

write code to determine if the 3rd and 22nd bits starting from the right of an interger are setSolutionHi, Please find my Java progrma. You have not mentioned a

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site