text unsigned long long with base to String

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了text unsigned long long with base to String相关的知识,希望对你有一定的参考价值。

std::string toString(unsigned long long n, uint8_t base)
{
  unsigned char buf[16 * sizeof(long)]; // Assumes 8-bit chars. 
  unsigned long long i = 0;  
  if (n == 0) { return "0"; };

  while (n > 0) {
    buf[i++] = n % base;
    n /= base;
  }
  
  std::string stringBuffer;
  for (; i > 0; i--) {
    stringBuffer += (
      buf[i - 1] < 10
        ? '0' + buf[i - 1]
        : 'A' + buf[i - 1] - 10
     );
  };
  return stringBuffer;
}

以上是关于text unsigned long long with base to String的主要内容,如果未能解决你的问题,请参考以下文章

如何将 unsigned long long int 转换为 unsigned char*?

char,short ,int ,long,long long,unsigned long long数据范围

char,short ,int ,long,long long,unsigned long long数据范围

char,short ,int ,long,long long,unsigned long long数据范围

c语言里的无符号unsigned long ulZ = unsigned long dJDM,在java里怎么办?用long型没有c那么大的数值。

unsigned long long类型与long long类型