Hello, let me link you to a similar topic: Arduino Forum
But still, your idea of using sprintf could work, if you understand that an array of size 5 can hold 5 elements: 0, 1, 2, 3, 4. And, as said, the string must have enough room for (in your case) 7 characters: '1', '2', '3', '4', '5', '6', '\0'.
That will work for '0' to '9', but fail rather miserably for 'A' to 'F'.
True but using sprintf(buff, "%.6u", testNumber) should not include them? And yepp I know this is another problem with original code. After fixing the number format for sprintf we will need to get back to how to map character '0'..'9' and 'A'..'F' to number 0..15.