title: Swap Bits In A Given Number
signature: class Solution {
  
      public Integer swapBitsInAGivenNumber(Integer x, Integer p1, Integer p2, Integer n) {
test_code: import static java.util.Map.entry;  
  import java.util.*;
  import java.lang.*;
  // TESTING CODE 
  // ============================================
  class QuestionEvaluator {
      public static String validateSolution(Integer x, Integer p1, Integer p2, Integer n, Integer expected){
          try{
              Driver driver = new Driver();
              if (driver.run(x, p1, p2, n,expected)){
                  return "PASSED";
              }
              return "FAILED";
              
          } catch (Exception exception_obj){
              return exception_obj.getClass().getSimpleName();
          }
  
      }
      public static void main(String[] args) {
          String result;
          result = validateSolution(95, 88, 97, 92, 95);
          System.out.println(String.format("%s%s","TEST-0...",result));    
      
          result = validateSolution(16, 26, 59, 42, 16);
          System.out.println(String.format("%s%s","TEST-1...",result));    
      
          result = validateSolution(55, 56, 40, 41, 55);
          System.out.println(String.format("%s%s","TEST-2...",result));    
      
          result = validateSolution(75, 35, 79, 30, 75);
          System.out.println(String.format("%s%s","TEST-3...",result));    
      
          result = validateSolution(90, 12, 59, 34, 90);
          System.out.println(String.format("%s%s","TEST-4...",result));    
      
          result = validateSolution(58, 65, 25, 19, 58);
          System.out.println(String.format("%s%s","TEST-5...",result));    
      
          result = validateSolution(69, 64, 17, 94, 69);
          System.out.println(String.format("%s%s","TEST-6...",result));    
      
          result = validateSolution(36, 33, 97, 44, 36);
          System.out.println(String.format("%s%s","TEST-7...",result));    
      
          result = validateSolution(62, 69, 66, 9, 62);
          System.out.println(String.format("%s%s","TEST-8...",result));    
      
      }
  }
  
  class Driver{
      public boolean run(Integer x, Integer p1, Integer p2, Integer n, Integer expected){
  
          PLACEHOLDER_CLS_NAME sol = new PLACEHOLDER_CLS_NAME();
          return validateSolution(sol.PLACEHOLDER_FN_NAME(x, p1, p2, n),expected);
      }
      
      public boolean validateSolution(Integer actual, Integer expected){
          return actual.equals(expected);
      }
  }
  
  
  // SOLUTION CODE
  // ============================================
  PLACEHOLDER_CODE_BODY
source_py: def swap_bits_in_a_given_number(x, p1, p2, n):
      set1 = ((x >> p1) & ((1 << n) - 1))
      set2 = ((x >> p2) & ((1 << n) - 1))
      xor = (set1 ^ set2)
      xor = ((xor << p1) | (xor << p2))
      result = (x ^ xor)
      return result
source_cpp: int swap_bits_in_a_given_number(unsigned int x, unsigned int p1, unsigned int p2, unsigned int n) {
    unsigned int set1 = ( x >> p1 ) & ( ( 1U << n ) - 1 );
    unsigned int set2 = ( x >> p2 ) & ( ( 1U << n ) - 1 );
    unsigned int Xor = ( set1 ^ set2 );
    Xor = ( Xor << p1 ) | ( Xor << p2 );
    unsigned int result = x ^ Xor;
    return result;
  }