#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include <assert.h>
typedef union {
// UINT64_MAX is 20 bytes.
// 23 bytes of zeros for copying.
char view_8[20 + 23];
uint64_t view_64[3];
} Print_Buffer;
void print_internal_uint64_t(uint64_t v) {
Print_Buffer output = {0};
size_t i = 0;
//printf("%lu - ", v);
while(true) {
uint64_t v_next = v / 10000;
uint64_t vXXXX = v % 10000;
uint64_t v__XX = vXXXX % 100;
uint64_t vXX__ = vXXXX / 100;
uint64_t v___X = v__XX % 10;
uint64_t v__X_ = v__XX / 10;
uint64_t v_X__ = vXX__ % 10;
uint64_t vX___ = vXX__ / 10;
output.view_8[20 - i - 1] = v___X + '0';
output.view_8[20 - i - 2] = v__X_ + '0';
output.view_8[20 - i - 3] = v_X__ + '0';
output.view_8[20 - i - 4] = vX___ + '0';
i += 4;
v = v_next;
if(v == 0) {
break;
}
}
for(size_t j = 0; j < 3; ++j) {
if(output.view_8[20 - i] != '0')
break;
output.view_8[20 - i] = 0;
i -= 1;
}
memmove(&output.view_8[0], &output.view_8[20 - i], 24);
printf("%s\n", output.view_8);
}
void print_n(uint64_t v) {
printf("uint64_t: ");
print_internal_uint64_t(v);
}
void print_n(int64_t v) {
printf("int64_t: ");
if(v < 0) {
printf("-");
v = -v;
}
print_internal_uint64_t(v);
}
int main() {
print_n(1234L);
print_n(10000L);
print_n(UINT64_MAX);
print_n(18446744073709551);
print_n(0UL);
print_n(1UL);
print_n(9UL);
print_n(50UL);
print_n(62UL);
print_n(73L);
print_n(-84L);
print_n(99999999L);
print_n(45645656L);
print_n(35123123123L);
print_n(4564565645645656L);
return 0;
}