> For the complete documentation index, see [llms.txt](https://851958789.gitbook.io/notes/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://851958789.gitbook.io/notes/0371_sum_of_two_integers/slt.md).

# Solution1 bit operation

* t-complexity $O(C)$

  &#x20; C is const with value 32
* s-complexity $O(1)$

iterate from low to high decimal

three cases of current bits:

* both bits are 1, current value depends on carry, and next carry = 1
* only one of the bits is 1
  * if carry is 1, then current value is 0, and next carry keeps 1
  * if carry is 0, then current value is 1, and next carry keeps 0

    these two cases can be summarized as res |= ((carry ^ 1) << i), and carry remain
* none of these bits are 0, current value is carry, next carry is 0
