title: Swap Bits In A Given Number
signature: pub fn swap_bits_in_a_given_number(x: i32, p1: i32, p2: i32, n: i32) -> i32 {
test_code: use std::collections::HashMap;
  use std::collections::HashSet;
  use std::cmp::*;
  use std::collections::*;
  use std::fmt::*; 
  
  
  // SOLUTION CODE
  // ============================================
  PLACEHOLDER_CODE_BODY
  
  // TESTING CODE 
  // ============================================
  pub fn validate_solution(actual: i32, expected: i32)->bool{
  return actual==expected
  }
  pub fn driver(x: i32, p1: i32, p2: i32, n: i32, expected: i32)->String{
      if validate_solution(PLACEHOLDER_FN_NAME(x, p1, p2, n), expected) {
        return "PASSED".to_string();
      };
      return "FAILED".to_string();
  
  }
  
  fn main() {
      println!("TEST-0...{}", driver(
        95, 88, 97, 92, 
        95
      ));
      
      println!("TEST-1...{}", driver(
        16, 26, 59, 42, 
        16
      ));
      
      println!("TEST-2...{}", driver(
        55, 56, 40, 41, 
        55
      ));
      
      println!("TEST-3...{}", driver(
        75, 35, 79, 30, 
        75
      ));
      
      println!("TEST-4...{}", driver(
        90, 12, 59, 34, 
        90
      ));
      
      println!("TEST-5...{}", driver(
        58, 65, 25, 19, 
        58
      ));
      
      println!("TEST-6...{}", driver(
        69, 64, 17, 94, 
        69
      ));
      
      println!("TEST-7...{}", driver(
        36, 33, 97, 44, 
        36
      ));
      
      println!("TEST-8...{}", driver(
        62, 69, 66, 9, 
        62
      ));
      
  }
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;
  }