| ... | @@ -40,7 +40,7 @@ static uint8_t digit_to_char(uint8_t digit, bool uppercase) { | ... | @@ -40,7 +40,7 @@ static uint8_t digit_to_char(uint8_t digit, bool uppercase) { |
| 40 | if (digit <= 9) { | 40 | if (digit <= 9) { |
| 41 | return digit + '0'; | 41 | return digit + '0'; |
| 42 | } else if (digit <= 35) { | 42 | } else if (digit <= 35) { |
| 43 | return digit + (uppercase ? 'A' : 'a'); | 43 | return (digit - 10) + (uppercase ? 'A' : 'a'); |
| 44 | } else { | 44 | } else { |
| 45 | zig_unreachable(); | 45 | zig_unreachable(); |
| 46 | } | 46 | } |
| ... | @@ -1545,6 +1545,10 @@ void bigint_append_buf(Buf *buf, const BigInt *op, uint64_t base) { | ... | @@ -1545,6 +1545,10 @@ void bigint_append_buf(Buf *buf, const BigInt *op, uint64_t base) { |
| 1545 | buf_appendf(buf, "%" ZIG_PRI_u64, op->data.digit); | 1545 | buf_appendf(buf, "%" ZIG_PRI_u64, op->data.digit); |
| 1546 | return; | 1546 | return; |
| 1547 | } | 1547 | } |
| | 1548 | if (op->digit_count == 1 && base == 16) { |
| | 1549 | buf_appendf(buf, "%" ZIG_PRI_x64, op->data.digit); |
| | 1550 | return; |
| | 1551 | } |
| 1548 | size_t first_digit_index = buf_len(buf); | 1552 | size_t first_digit_index = buf_len(buf); |
| 1549 | | 1553 | |
| 1550 | BigInt digit_bi = {0}; | 1554 | BigInt digit_bi = {0}; |
| ... | @@ -1556,7 +1560,7 @@ void bigint_append_buf(Buf *buf, const BigInt *op, uint64_t base) { | ... | @@ -1556,7 +1560,7 @@ void bigint_append_buf(Buf *buf, const BigInt *op, uint64_t base) { |
| 1556 | bigint_init_bigint(a, op); | 1560 | bigint_init_bigint(a, op); |
| 1557 | | 1561 | |
| 1558 | BigInt base_bi = {0}; | 1562 | BigInt base_bi = {0}; |
| 1559 | bigint_init_unsigned(&base_bi, 10); | 1563 | bigint_init_unsigned(&base_bi, base); |
| 1560 | | 1564 | |
| 1561 | for (;;) { | 1565 | for (;;) { |
| 1562 | bigint_rem(&digit_bi, a, &base_bi); | 1566 | bigint_rem(&digit_bi, a, &base_bi); |
| ... | @@ -1574,7 +1578,7 @@ void bigint_append_buf(Buf *buf, const BigInt *op, uint64_t base) { | ... | @@ -1574,7 +1578,7 @@ void bigint_append_buf(Buf *buf, const BigInt *op, uint64_t base) { |
| 1574 | } | 1578 | } |
| 1575 | | 1579 | |
| 1576 | // reverse | 1580 | // reverse |
| 1577 | for (size_t i = first_digit_index; i < buf_len(buf); i += 1) { | 1581 | for (size_t i = first_digit_index; i < buf_len(buf) / 2; i += 1) { |
| 1578 | size_t other_i = buf_len(buf) + first_digit_index - i - 1; | 1582 | size_t other_i = buf_len(buf) + first_digit_index - i - 1; |
| 1579 | uint8_t tmp = buf_ptr(buf)[i]; | 1583 | uint8_t tmp = buf_ptr(buf)[i]; |
| 1580 | buf_ptr(buf)[i] = buf_ptr(buf)[other_i]; | 1584 | buf_ptr(buf)[i] = buf_ptr(buf)[other_i]; |