Skip to content

proposed solution for add 2 integers with max bit length #207

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

pupipipu
Copy link

The bitwise add 2 integers solution will hit infinite loop for negative integers. Added max bit length to avoid exception

" if carry != 0:\n",
" return self.sum_two(result, carry)\n",
" return result;"
" #max bit length, change to 32 for 32bit\n",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a single space between # and the comments according to PEP8.

" while b != 0:\n",
" if b == max_positive:\n",
" return a ^ min_negative\n",
" a,b = a ^ b,(a&b)<<1\n",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am reading this just at github.

Here, the 4 space are correct? or there are less?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants