title: Swap Two Nibbles Byte
signature: function swapTwoNibblesByte(x: number): number {
source_py: def swap_two_nibbles_byte(x):
      return (((x & 15) << 4) | ((x & 240) >> 4))
source_cpp: int swap_two_nibbles_byte(int x) {
    return ( ( x & 0x0F ) << 4 | ( x & 0xF0 ) >> 4 );
  }
question_info.test_list: [{"idx": 0, "outputs": 147, "inputs": {"x": 57}}, {"idx": 1, "outputs": 54, "inputs": {"x": 99}}, {"idx": 2, "outputs": 36, "inputs": {"x": 66}}, {"idx": 3, "outputs": 22, "inputs": {"x": 97}}, {"idx": 4, "outputs": 245, "inputs": {"x": 95}}, {"idx": 5, "outputs": 162, "inputs": {"x": 42}}, {"idx": 6, "outputs": 245, "inputs": {"x": 95}}, {"idx": 7, "outputs": 149, "inputs": {"x": 89}}, {"idx": 8, "outputs": 48, "inputs": {"x": 3}}, {"idx": 9, "outputs": 69, "inputs": {"x": 84}}]
question_info.entry_cls_name: Solution
question_info.test_code: 
  
  // SOLUTION CODE
  // ============================================
  PLACEHOLDER_CODE_BODY
  
  // TESTING CODE 
  // ============================================
  function convertToString(value: any): string{
      return JSON.stringify(value, function (key, val) {
          if (val instanceof Set) {
              return Array.from(val);
          } return val;});
  }
  
  function validateSolution(actual: number, expected: number): boolean {
      return convertToString(actual) === convertToString(expected);
  }
  
  function driver(x: number, expected:number): string {
      try{
          if (validateSolution(PLACEHOLDER_FN_NAME(x),expected)){
              return "PASSED";
          }
          return "FAILED";
      } catch (error) {
        return error.name;
      }
      
  }
      
  function main(){
    let result = '';
    result = driver(57, 147);
    console.log(`TEST-0...${result}`);
  
    result = driver(99, 54);
    console.log(`TEST-1...${result}`);
  
    result = driver(66, 36);
    console.log(`TEST-2...${result}`);
  
    result = driver(97, 22);
    console.log(`TEST-3...${result}`);
  
    result = driver(95, 245);
    console.log(`TEST-4...${result}`);
  
    result = driver(42, 162);
    console.log(`TEST-5...${result}`);
  
    result = driver(95, 245);
    console.log(`TEST-6...${result}`);
  
    result = driver(89, 149);
    console.log(`TEST-7...${result}`);
  
    result = driver(3, 48);
    console.log(`TEST-8...${result}`);
  
    result = driver(84, 69);
    console.log(`TEST-9...${result}`);
  
  };
  
  main();
question_info.extension: ts
question_info.entry_fn_name: swapTwoNibblesByte
question_info.test_case_ids: 0 1 2 3 4 5 6 7 8 9
question_info.commands: tsc --target es2020 --lib es5,dom,es2015,es2020 __FILENAME__
question_info.commands: node __FILENAME__.js