From the course: Python Essential Training

Unlock the full course today

Join today to access over 23,200 courses taught by industry experts.

Solution: Converting hex to decimal

Solution: Converting hex to decimal - Python Tutorial

From the course: Python Essential Training

Solution: Converting hex to decimal

- [Instructor] All right. I hope the hex didn't vex you too much. I have two solutions that I want to go over with you, and the first is pretty straightforward. So here I'm assuming that everything passed into this function is a string, or rather a list of characters is another way to think about it. And the only test cases I gave you were strings. So if you did check for integers or some other really wacky input, you are a more thorough and diligent programmer than I am. Good work, but I was really only worried about strings here. Just as an upfront check, I go through every character in hexNum and just make sure that it's in our dictionary up here. And if it is in our dictionary, then I know I can process it. So there are three cases, three character strings, two character strings, and one character strings. For the three character strings, I take the leftmost character, so that's the character index zero, and multiply it by 256 or 16 squared. Remember, this is the 256th place in a…

Contents