posint morph code size benchmark

This commit is contained in:
Michael Sippel 2025-02-03 17:05:19 +01:00
parent e500a24d2a
commit 23b2dcaf82
Signed by: senvas
GPG key ID: F96CF119C34B64A6
4 changed files with 149 additions and 57 deletions

View file

@ -0,0 +1,47 @@
#include <stdio.h>
#include <stdint.h>
int main() {
char bufA[1024];
char bufB[1024];
char * in = bufA;
char * out = bufB;
scanf("%s", in);
uint64_t value = 0;
while( *in ) {
if( *in >= '0' && *in <= '9' ) {
value *= 10;
value += *in - '0';
}
else
return -1;
in++;
}
uint64_t v = value;
while( v ) {
out ++;
v /= 16;
}
*out-- = '\0';
while( value ) {
unsigned digit = value % 16;
if( digit < 10 ) {
*out-- = digit + '0';
} else if( digit < 16 ) {
*out-- = digit + 'a' - 10;
} else {
return -1;
}
value /= 16;
}
printf("%s\n", out);
return 0;
}