2025-02-03 17:05:19 +01:00
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <stdint.h>
|
|
|
|
|
#include <morphisms/length-prefix.h>
|
|
|
|
|
#include <morphisms/posint.h>
|
|
|
|
|
|
2025-02-14 13:51:59 +01:00
|
|
|
|
__attribute__((noinline))
|
|
|
|
|
int morph_posint_radix(
|
|
|
|
|
uint8_t * bufA,
|
|
|
|
|
uint8_t * bufB
|
|
|
|
|
) {
|
2025-02-03 17:05:19 +01:00
|
|
|
|
// morph to
|
|
|
|
|
// ℕ ~ <PosInt 10 BigEndian> ~ [~<LengthPrefix x86.UInt64> <Digit 10> ~ Char ~ Ascii]
|
|
|
|
|
{
|
|
|
|
|
char const * src = (void*) bufA;
|
|
|
|
|
struct LengthPrefixUInt8Array * dst = (void*) bufB;
|
|
|
|
|
morph_string_as_nullterm_to_length_prefix( src, dst );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// morph to
|
|
|
|
|
// ℕ ~ <PosInt 10 BigEndian> ~ [~<LengthPrefix x86.UInt64> <Digit 10> ~ ℤ_10 ~ x86.UInt64]
|
|
|
|
|
{
|
|
|
|
|
struct LengthPrefixUInt8Array * src = (void*) bufB;
|
|
|
|
|
struct LengthPrefixUInt64Array * dst = (void*) bufA;
|
2025-02-05 11:25:53 +01:00
|
|
|
|
length_prefix_array_map_8_to_64( morph_digit_as_char_to_uint64, src, dst );
|
2025-02-03 17:05:19 +01:00
|
|
|
|
}
|
|
|
|
|
// ℕ ~ <PosInt 16 LittleEndian> ~ [~<LengthPrefix x86.UInt64> <Digit 16> ~ ℤ_16 ~ x86.UInt64]
|
|
|
|
|
{
|
|
|
|
|
uint64_t const src_radix = 10;
|
|
|
|
|
uint64_t const dst_radix = 16;
|
|
|
|
|
struct LengthPrefixUInt64Array * src = (void*) bufB;
|
|
|
|
|
struct LengthPrefixUInt64Array * dst = (void*) bufA;
|
2025-02-14 13:51:59 +01:00
|
|
|
|
morph_posint_radix_little( src_radix, dst_radix, src, dst );
|
2025-02-03 17:05:19 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// morph to
|
|
|
|
|
// ℕ ~ <PosInt 16 BigEndian> ~ [~<LengthPrefix x86.UInt64> <Digit 16> ~ Char ~ Ascii]
|
|
|
|
|
{
|
|
|
|
|
struct LengthPrefixUInt64Array * src = (void*) bufB;
|
|
|
|
|
struct LengthPrefixUInt8Array * dst = (void*) bufA;
|
|
|
|
|
|
2025-02-05 11:25:53 +01:00
|
|
|
|
length_prefix_array_map_64_to_8( morph_digit_as_uint64_to_char, src, dst );
|
2025-02-03 17:05:19 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// morph to
|
|
|
|
|
// ℕ ~ <PosInt 16 BigEndian> ~ [~<ValueDelim '\0'> <Digit 16> ~ Char ~ Ascii]
|
|
|
|
|
{
|
|
|
|
|
struct LengthPrefixUInt8Array * src = (void*) bufA;
|
|
|
|
|
char * dst = (void*) bufB;
|
|
|
|
|
morph_string_as_length_prefix_to_nullterm( src, dst );
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-14 13:51:59 +01:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int main() {
|
|
|
|
|
uint8_t bufA[1024];
|
|
|
|
|
uint8_t bufB[1024];
|
|
|
|
|
|
|
|
|
|
scanf("%s", bufA);
|
|
|
|
|
morph_posint_radix( bufA, bufB );
|
2025-02-03 17:05:19 +01:00
|
|
|
|
printf("%s\n", bufB);
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|