This notebook was prepared by Donne Martin. Source and license info is on GitHub.

- Can we assume the input is always a positive int?
- Yes

- Can we assume we're working with 32 bits?
- Yes

- Is the output an int?
- Yes

- Can we assume the inputs are valid (not None)?
- No

- Can we assume this fits memory?
- Yes

- None -> Exception
- 0 -> 0
- -1 -> -1
- General case
input = 1001 1111 0110 result = 0110 1111 1001

Refer to the Solution Notebook. If you are stuck and need a hint, the solution notebook's algorithm discussion might be a good place to start.

In [ ]:

```
class Bits(object):
def pairwise_swap(self, num):
# TODO: Implement me
pass
```

**The following unit test is expected to fail until you solve the challenge.**

In [ ]:

```
# %load test_pairwise_swap.py
import unittest
class TestBits(unittest.TestCase):
def test_pairwise_swap(self):
bits = Bits()
self.assertEqual(bits.pairwise_swap(0), 0)
self.assertEqual(bits.pairwise_swap(1), 1)
num = int('0000100111110110', base=2)
expected = int('0000011011111001', base=2)
self.assertEqual(bits.pairwise_swap(num), expected)
print('Success: test_pairwise_swap')
def main():
test = TestBits()
test.test_pairwise_swap()
if __name__ == '__main__':
main()
```

Review the Solution Notebook for a discussion on algorithms and code solutions.