Possible bug in to_hstring()
skilz80 opened this issue · 1 comments
If you pass an unsigned value without a leading 0x
into this function, it will print alpha characters that exceed the letter F
.
Try running this in your kernel:
newRenderer.Print( to_hstring((uint64_t)375896) );
On my running instance, this will print:
000000000005LM58
Which is clearly not a decimal nor hexadecimal value.
You might want to consider allowing this function to by default accept 0x*****
and perform it normally, and to also accept a regular unsigned decimal value, but when it does, convert that decimal value into a hex
value first.
Here's a link to compiler explorer, and this is producing the same output that I'm seeing printed when running my kernel: https://godbolt.org/z/ef1qrE
Okay, for those coming to this github repo, the actual posted code on this github is correct, there is no bug within the to_hstring()
function. However, within the YouTube video when you come across it for the first time, there is a bug in the code.
Within the ternary expression, he is comparing ( tmp > 9 ? 'A' : '0' );
and this will give the wrong result if you pass a regular decimal value to it without a preceding 0x
in the value. In the source code for this repository, he does have the correct implementation. He does have: ( tmp > 9 ? 55 : '0' );
which does produce the correct output.