Java: Convert Decimal Integer to Hexadecimal ASCII String
Date: 2014-02-19 |
**Problem: **Convert a decimal integer to an ASCII string in hexadecimal without using built-in library functions.
As you should know, hexadecimal is base 16. A simple guide to converting from decimal to hex can be found here.
On to the code:
(https://gist.github.com/SIRHAMY/9087140)I started by creating the result variable that will be used to store the returned value.
Next, I created an array to easily access the hexadecimal equivalent of each number (0-15).
I then created a loop that continually adds the remainder of the number remaining divided by 16 to the front of the result string. After this action takes place, the number remaining is divided by 16. This continues until the remaining total is less than 16, where that hex value is added to the beginning of the result string then returned.
Want more like this?
The best / easiest way to support my work is by subscribing for future updates and sharing with your network.