However, my integer to hex function gets stuck in an infinite loop and I have no clue why.
You never change the value of number inside the loop. The algorithm should be dividing it by 16 and storing the result, right? Also, 0 and '0' are two completely different values. Be sure to double check whether you are working in a string context or a numeric context and use the right constants.
n = number;
This will probably give you problems as well. The expression should be the other way around because number is the variable you are trying to initialize.