Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6799061
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T18:48:13+00:00 2026-05-26T18:48:13+00:00

I’m trying to convert a 128-bit unsigned integer stored as an array of 4

  • 0

I’m trying to convert a 128-bit unsigned integer stored as an array of 4 unsigned ints to the decimal string representation in C:

unsigned int src[] = { 0x12345678, 0x90abcdef, 0xfedcba90, 0x8765421 };
printf("%s", some_func(src)); // gives "53072739890371098123344"

(The input and output examples above are completely fictional; I have no idea what that input would produce.)

If I was going to hex, binary or octal, this would be a simple matter of masks and bit shifts to peel of the least significant characters. However, it seems to me that I need to do base-10 division. Unfortunately, I can’t remember how to do that across multiple ints, and the system I’m using doesn’t support data types larger than 32-bits, so using a 128-bit type is not possible. Using a different language is also out, and I’d rather avoid a big number library just for this one operation.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T18:48:13+00:00Added an answer on May 26, 2026 at 6:48 pm

    Division is not necessary:

    #include <string.h>
    #include <stdio.h>
    
    typedef unsigned long uint32;
    
    /* N[0] - contains least significant bits, N[3] - most significant */
    char* Bin128ToDec(const uint32 N[4])
    {
      // log10(x) = log2(x) / log2(10) ~= log2(x) / 3.322
      static char s[128 / 3 + 1 + 1];
      uint32 n[4];
      char* p = s;
      int i;
    
      memset(s, '0', sizeof(s) - 1);
      s[sizeof(s) - 1] = '\0';
    
      memcpy(n, N, sizeof(n));
    
      for (i = 0; i < 128; i++)
      {
        int j, carry;
    
        carry = (n[3] >= 0x80000000);
        // Shift n[] left, doubling it
        n[3] = ((n[3] << 1) & 0xFFFFFFFF) + (n[2] >= 0x80000000);
        n[2] = ((n[2] << 1) & 0xFFFFFFFF) + (n[1] >= 0x80000000);
        n[1] = ((n[1] << 1) & 0xFFFFFFFF) + (n[0] >= 0x80000000);
        n[0] = ((n[0] << 1) & 0xFFFFFFFF);
    
        // Add s[] to itself in decimal, doubling it
        for (j = sizeof(s) - 2; j >= 0; j--)
        {
          s[j] += s[j] - '0' + carry;
    
          carry = (s[j] > '9');
    
          if (carry)
          {
            s[j] -= 10;
          }
        }
      }
    
      while ((p[0] == '0') && (p < &s[sizeof(s) - 2]))
      {
        p++;
      }
    
      return p;
    }
    
    int main(void)
    {
      static const uint32 testData[][4] =
      {
        { 0, 0, 0, 0 },
        { 1048576, 0, 0, 0 },
        { 0xFFFFFFFF, 0, 0, 0 },
        { 0, 1, 0, 0 },
        { 0x12345678, 0x90abcdef, 0xfedcba90, 0x8765421 }
      };
      printf("%s\n", Bin128ToDec(testData[0]));
      printf("%s\n", Bin128ToDec(testData[1]));
      printf("%s\n", Bin128ToDec(testData[2]));
      printf("%s\n", Bin128ToDec(testData[3]));
      printf("%s\n", Bin128ToDec(testData[4]));
      return 0;
    }
    

    Output:

    0
    1048576
    4294967295
    4294967296
    11248221411398543556294285637029484152
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
I've got a string that has curly quotes in it. I'd like to replace
Specifically, suppose I start with the string string =hello \'i am \' me And
I am trying to loop through a bunch of documents I have to put
I have a bunch of posts stored in text files formatted in yaml/textile (from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.