This notebook was prepared by Donne Martin. Source and license info is on GitHub.
i = 2 j = 6 n = 0000 0100 0000 0000 m = 0000 0000 0001 0011 result = 0000 0100 0100 1100
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.
class Bits(object):
def insert_m_into_n(self, m, n, i, j):
# TODO: Implement me
pass
The following unit test is expected to fail until you solve the challenge.
# %load test_insert_m_into_n.py
import unittest
class TestBit(unittest.TestCase):
def test_insert_m_into_n(self):
n = int('0000010000111101', base=2)
m = int('0000000000010011', base=2)
expected = int('0000010001001101', base=2)
bits = Bits()
self.assertEqual(bits.insert_m_into_n(m, n, i=2, j=6), expected)
print('Success: test_insert_m_into_n')
def main():
test = TestBit()
test.test_insert_m_into_n()
if __name__ == '__main__':
main()
Review the Solution Notebook for a discussion on algorithms and code solutions.