title: Swap All Odd And Even Bits
signature: func swapAllOddAndEvenBits(x int) int {
test_code: package main
  
  import (
      "fmt"
      "reflect"
      "math"
      "sort"
  )
  
  // SOLUTION CODE
  // ===================================
  PLACEHOLDER_CODE_BODY
  
  // TESTING CODE
  // ===================================
  func validateSolution(actual int, expected int) bool {
      return reflect.DeepEqual(actual,expected)
  }
  
  func driver(x int, expected int) string {
      if validateSolution(PLACEHOLDER_FN_NAME(x),expected) {
              return "PASSED"
      }
      return "FAILED"
  
  }
  
  func main() {
  
      // Use imports to avoid undefined errors
      var _ = reflect.DeepEqual
      _ = math.Abs
      _ = sort.Sort
      result := ""
      result = driver(99, 147)
      fmt.Printf("TEST-0...%s\n", result)
      
      result = driver(94, 173)
      fmt.Printf("TEST-1...%s\n", result)
      
      result = driver(11, 7)
      fmt.Printf("TEST-2...%s\n", result)
      
      result = driver(3, 3)
      fmt.Printf("TEST-3...%s\n", result)
      
      result = driver(77, 142)
      fmt.Printf("TEST-4...%s\n", result)
      
      result = driver(57, 54)
      fmt.Printf("TEST-5...%s\n", result)
      
      result = driver(54, 57)
      fmt.Printf("TEST-6...%s\n", result)
      
      result = driver(66, 129)
      fmt.Printf("TEST-7...%s\n", result)
      
      result = driver(98, 145)
      fmt.Printf("TEST-8...%s\n", result)
      
      result = driver(36, 24)
      fmt.Printf("TEST-9...%s\n", result)
      
          
  }
source_py: def swap_all_odd_and_even_bits(x):
      even_bits = (x & 2863311530)
      odd_bits = (x & 1431655765)
      even_bits >>= 1
      odd_bits <<= 1
      return (even_bits | odd_bits)
source_cpp: unsigned int swap_all_odd_and_even_bits(unsigned int x) {
    unsigned int even_bits = x & 0xAAAAAAAA;
    unsigned int odd_bits = x & 0x55555555;
    even_bits >>= 1;
    odd_bits <<= 1;
    return ( even_bits | odd_bits );
  }