"This notebook was prepared by [Donne Martin](https://github.com/donnemartin). Source and license info is on [GitHub](https://github.com/donnemartin/interactive-coding-challenges)."
]
},
{
"cell_type":"markdown",
"metadata":{},
"source":[
"# Challenge Notebook"
]
},
{
"cell_type":"markdown",
"metadata":{},
"source":[
"## Problem: Implement common bit manipulation operations: get_bit, set_bit, clear_bit, clear_bits_msb_to_index, clear_bits_msb_to_lsb, update_bit.\n",
"\n",
"* [Constraints](#Constraints)\n",
"* [Test Cases](#Test-Cases)\n",
"* [Algorithm](#Algorithm)\n",
"* [Code](#Code)\n",
"* [Unit Test](#Unit-Test)\n",
"* [Solution Notebook](#Solution-Notebook)"
]
},
{
"cell_type":"markdown",
"metadata":{},
"source":[
"## Constraints\n",
"\n",
"* Can we assume the inputs are valid?\n",
" * No\n",
"* Can we assume this fits memory?\n",
" * Yes"
]
},
{
"cell_type":"markdown",
"metadata":{},
"source":[
"## Test Cases\n",
"\n",
"* None as a number input -> Exception\n",
"* Negative index -> Exception\n",
"\n",
"### get_bit\n",
" number = 0b10001110, index = 3\n",
" expected = True\n",
"### set_bit\n",
" number = 0b10001110, index = 4\n",
" expected = 0b10011110\n",
"### clear_bit\n",
" number = 0b10001110, index = 3\n",
" expected = 0b10000110\n",
"### clear_bits_msb_to_index\n",
" number = 0b10001110, index = 3\n",
" expected = 0b00000110\n",
"### clear_bits_index_to_lsb\n",
" number = 0b10001110, index = 3\n",
" expected = 0b10000000\n",
"### update_bit\n",
" number = 0b10001110, index = 3, value = 1\n",
" expected = 0b10001110\n",
" number = 0b10001110, index = 3, value = 0\n",
" expected = 0b10000110\n",
" number = 0b10001110, index = 0, value = 1\n",
" expected = 0b10001111"
]
},
{
"cell_type":"markdown",
"metadata":{},
"source":[
"## Algorithm\n",
"\n",
"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."