Improve conversion to base 16 and print errors more clearly