input: Write a python function to toggle bits of the number except the first and the last bit.
  assert toggle_middle_bits(9) == 15
  assert toggle_middle_bits(10) == 12
  assert toggle_middle_bits(11) == 13
  
output: def toggle_middle_bits(n):
      mask = (1 << (n.bit_length() - 1)) - 2
      return (n & 1) | (~n & mask) | (n & (1 << (n.bit_length() - 1)))