#include <stdio.h>
#include <string.h>

void MulBytesBy10(unsigned char* buf, size_t cnt)
{
  unsigned carry = 0;
  while (cnt--)
  {
    carry += 10 * *buf;
    *buf++ = carry & 0xFF;
    carry >>= 8;
  }
}

void AddDigitToBytes(unsigned char* buf, size_t cnt, unsigned char digit)
{
  unsigned carry = digit;
  while (cnt-- && carry)
  {
    carry += *buf;
    *buf++ = carry & 0xFF;
    carry >>= 8;
  }
}

void DecimalIntegerStringToBytes(unsigned char* buf, size_t cnt, const char* str)
{
  memset(buf, 0, cnt);

  while (*str != '\0')
  {
    MulBytesBy10(buf, cnt);
    AddDigitToBytes(buf, cnt, *str++ - '0');
  }
}

void PrintBytesHex(const unsigned char* buf, size_t cnt)
{
  size_t i;
  for (i = 0; i < cnt; i++)
    printf("%02X", buf[cnt - 1 - i]);
}

int main(void)
{
  unsigned char buf[16];

  DecimalIntegerStringToBytes(buf, sizeof buf, "11234567890123456789112345678911");

  PrintBytesHex(buf, sizeof buf); puts("");

  return 0;
}
