Skip to content

added decimal to hexadecimal conversion #977

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

Merged
merged 2 commits into from
Jul 9, 2019
Merged

added decimal to hexadecimal conversion #977

merged 2 commits into from
Jul 9, 2019

Conversation

jasper256
Copy link
Contributor

I didn't update the directory because I noticed that the other conversion algorithms were not listed

@PatOnTheBack
Copy link
Contributor

PatOnTheBack commented Jul 8, 2019

If I add this line print("999098 in hexadecimal is", decimal_to_hexadecimal(999098)) to the main() function, I get an error. Does your program not support large numbers?

('5 in hexadecimal is', '5')
('15 in hexadecimal is', 'f')
('37 in hexadecimal is', '25')
('255 in hexadecimal is', 'ff')
('4096 in hexadecimal is', '100')
Traceback (most recent call last):
  File "decimal_to_hex.py", line 45, in <module>
    main()
  File "decimal_to_hex.py", line 42, in main
    print("999098 in hexadecimal is", decimal_to_hexadecimal(999098))
  File "decimal_to_hex.py", line 30, in decimal_to_hexadecimal
    hexadecimal = values[remainder] + hexadecimal
KeyError: 235

This link might help you to troubleshoot the KeyError. https://wiki.python.org/moin/KeyError

@jasper256
Copy link
Contributor Author

Thank you for bringing this to my attention. After combing through the algorithm again I believe I have found the error that would cause the key to go out of bounds as the number of digits necessary increase. I will fix this as soon as I get home.

@jasper256
Copy link
Contributor Author

The program has now been revised. I used 999,098 as a test and checked the results with a calculator, which came back as successful.

Copy link
Member

@cclauss cclauss left a comment

Choose a reason for hiding this comment

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

Looks good. OPTIONAL: Our automated testing will run doctests so it would be really cool to add some of those.

@jasper256
Copy link
Contributor Author

I honestly don't know much about automated testing, but it's something I'd be happy to look into in the future. I'm currently about to head to the airport for a trip I'm taking, and I won't be able to sit down in front of a computer for a couple weeks. I won't even have internet access through my phone in a few days, so if anyone posts comments just know that I'll get to them when I can in about two weeks.

@cclauss cclauss merged commit 8b2d1b7 into TheAlgorithms:master Jul 9, 2019
@cclauss
Copy link
Member

cclauss commented Jul 9, 2019

Cool. Let's land this one now and you can pick up tests when you return. Read thru the doctest page on your flight because it is simple but really helpful to have tests on your code. Safe travels.

stokhos pushed a commit to stokhos/Python that referenced this pull request Jan 3, 2021
* added decimal to hexadecimal conversion

* fixed error occuring as more digits were needed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants