tutorialcup
Convert a Number to Hexadecimal Leetcode Solution
The problem Convert a Number to Hexadecimal Leetcode Solution provides us with an integer. Then asks us to convert the given integer in decimal number system to hexadecimal number system. More formally, the question requires us to convert an integer given in base 10 to a base 16 representation. We had already solved a problem where we were given a number in the decimal number system. And had to convert it into base 7. So, before moving on further, let's take a look at a few examples.
Example
26
1a
Explanation: This conversion is easy, if happen to know about the hexadecimal number system. But if you are unaware of it, just convert the given number into base 16 representation. We do that by repetitive division and storing remainder. One thing to note that, 10 is represented using 'a' in hexadecimal notation.
-1
ffffffff
Explanation: Since the negative numbers are stored as their 2's complement notation. The -1 in its 2s complement notation is 11111111111111111111111111111111. So, we just convert this into hexadecimal which is shown in the output.
Approach for Convert a Number to Hexadecimal Leetcode Solution
Before diving deep into the problem Convert a Number to Hexadecimal Leetcode Solution. Let's first familiarize ourselves with the hexadecimal number system. So, the hexadecimal number system is also like the decimal number system but the numbers 10 to 15 are represented using lower-case alphabets from 'a' to 'f'.
www.tutorialcup.com/leetcode-solutions/convert-a-number-t...
Convert a Number to Hexadecimal Leetcode Solution
The problem Convert a Number to Hexadecimal Leetcode Solution provides us with an integer. Then asks us to convert the given integer in decimal number system to hexadecimal number system. More formally, the question requires us to convert an integer given in base 10 to a base 16 representation. We had already solved a problem where we were given a number in the decimal number system. And had to convert it into base 7. So, before moving on further, let's take a look at a few examples.
Example
26
1a
Explanation: This conversion is easy, if happen to know about the hexadecimal number system. But if you are unaware of it, just convert the given number into base 16 representation. We do that by repetitive division and storing remainder. One thing to note that, 10 is represented using 'a' in hexadecimal notation.
-1
ffffffff
Explanation: Since the negative numbers are stored as their 2's complement notation. The -1 in its 2s complement notation is 11111111111111111111111111111111. So, we just convert this into hexadecimal which is shown in the output.
Approach for Convert a Number to Hexadecimal Leetcode Solution
Before diving deep into the problem Convert a Number to Hexadecimal Leetcode Solution. Let's first familiarize ourselves with the hexadecimal number system. So, the hexadecimal number system is also like the decimal number system but the numbers 10 to 15 are represented using lower-case alphabets from 'a' to 'f'.
www.tutorialcup.com/leetcode-solutions/convert-a-number-t...