Any solution to convert given char*(number) to required unsigned char*(hex of number)

Given For e.g,
char input[] = “10011210582553796”;

now Hexadecimal of 10011210582553796 is 2391249A8B74C4.

So output unsigned char* should have value,
unsigned char output[8] = {0x00,0x23,0x91,0x24,0x9A,0x8B,0x74,0xC4};

Any solution to convert given input char* to output char* with above mentioned requirement.

code should run on platform for which __int64/signed long long is not supported.

Thanx in advance…

Oh that’s a bugger. I don’t think the standard C library could do character manip for integers. Maybe some external library could do it. Try writing a procedure yourself.

i’d say make a function to convert the char* to a double (maybe a long double if double isnt big enough for you and you can support it) with double atof( const char string ); then do the math to convert to hex while putting it back into your output char[] (you can google how to convert decimal to hex)

[QUOTE=yaim0310;2354337]i’d say make a function to convert the char* to a double (maybe a long double if double isnt big enough for you and you can support it) with double atof( const char string ); then do the math to convert to hex while putting it back into your output char[] (you can google how to convert decimal to hex)[/QUOTE]
For the example passionpatel gave, double would be insufficiently small to hold a value that big. There needs to be character manipulation for arbitrarily large values.

I remember I wrote a large number factorial calculator based on character manipulation. It’s similar.

It might be helpful to look at how some high-level languages do it. For example, just quickly glancing through the Python source, it looks like [font=monospace] _PyInt_Format[/font] does the work in intobject.c (follow the link to the file, then search for that method).

well if you #include <stdint.h> you should be able to use uint64_t for multi-platform. thats the reason behind not using __int64 right?

What if I want to convert 3885738382393854839348378438948589394384384834839438483493843843 to hex?

You shouldnt let such big numbers run rapid in your programs.

found solution

 int number = 0;
 char numberchars[] = "10011210582553796";
 int i = 0;
 int ans = 0;
 int carry = 0;

 char answerArray[100] = {0};

 char remainderArray[100] = {0};
 int remindex = 0;
 int ansindex = 0;
 int remainder = 0;

 while( numberchars* != '\0' )
 {
      while( numberchars* != '\0' )
      {
           char currentchar[2] = {0};
           currentchar[0]=numberchars*;

           int num = atoi(currentchar);
           num += remainder;
           remainder = 0;

           if ( num &lt; 2  )
           {               
                remainder = num;
                if(i&gt;0)
                     answerArray[ansindex++] = '0';
           }
           else
           {
                remainder = num % 2;
                int answer = num / 2;

                char a[2] = {0};
                itoa(answer,a,10);

                answerArray[ansindex++] = a[0];
           }

           i++;
           remainder *= 10;
      }

      char a[2] = {0};
      int rval = remainder / 10;
      itoa(remainder / 10,a,10);
      
      remainderArray[remindex++] = a[0];
      int size = sizeof(answerArray);
      memcpy(numberchars,answerArray,sizeof(answerArray));
       size = sizeof(answerArray);
      memset(answerArray,0,sizeof(answerArray));
      ansindex = 0;
      remainder = 0;
      i=0;
 }

 char int64[8] = {0};

 for(int k=0;remainderArray[k]!= '\0';k++)
 {
      int64[7-(k/8)] |= ((remainderArray[k]-'0') &lt;&lt; (k%8));
 }

[quote=passionpatel;2354194]Given For e.g,
char input[] = “10011210582553796”;

now Hexadecimal of 10011210582553796 is 2391249A8B74C4.

So output unsigned char* should have value,
unsigned char output[8] = {0x00,0x23,0x91,0x24,0x9A,0x8B,0x74,0xC4};

Any solution to convert given input char* to output char* with above mentioned requirement.

code should run on platform for which __int64/signed long long is not supported.

Thanx in advance…[/quote]