Fix a bug in print_long_hex()

Because of order of shifting operations and a literal that defaulted
to int, the high 32 bits were printed incorrectly.
This commit is contained in:
Justin C. Miller
2020-05-10 02:31:53 -07:00
parent 10c8f6e4b5
commit 88ace0a99f

View File

@@ -126,7 +126,7 @@ console::print_hex(uint32_t n) const
wchar_t buffer[9]; wchar_t buffer[9];
wchar_t *p = buffer; wchar_t *p = buffer;
for (int i = 7; i >= 0; --i) { for (int i = 7; i >= 0; --i) {
uint8_t nibble = (n & (0xf << (i*4))) >> (i*4); uint8_t nibble = (n >> (i*4)) & 0xf;
*p++ = digits[nibble]; *p++ = digits[nibble];
} }
*p = 0; *p = 0;
@@ -140,7 +140,7 @@ console::print_long_hex(uint64_t n) const
wchar_t buffer[17]; wchar_t buffer[17];
wchar_t *p = buffer; wchar_t *p = buffer;
for (int i = 15; i >= 0; --i) { for (int i = 15; i >= 0; --i) {
uint8_t nibble = (n & (0xf << (i*4))) >> (i*4); uint8_t nibble = (n >> (i*4)) & 0xf;
*p++ = digits[nibble]; *p++ = digits[nibble];
} }
*p = 0; *p = 0;