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

  • Home
  • SEARCH
  • 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 541655
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T10:21:54+00:00 2026-05-13T10:21:54+00:00

Please provide some code for converting char[] array of decimal values to bytes array

  • 0

Please provide some code for converting char[] array of decimal values to bytes array for big integer value in c.

How can I convert this below code for big array of decimal value, such as I get the result as array of long bytes?

static int dec2bin (char inbuf[], int num_convert)
{
  char ctemp;
  int result, power;

  num_convert--; /* index of LS char to convert */
  result = 0;
  power = 1;
  while (num_convert >= 0)
  {
    ctemp = inbuf[num_convert--]; /* working digit */
    if (isdigit(ctemp))
    {
      result += ((ctemp-'0') * power);
      power *= 10;
    }
    else
      return(0); /* error: non-numeric digit detected */
  }
  return (result);
}

No it is not just long value , it is really a biginteger value , can anyone give a simple dec to byte(binary conversion logic , i will replace the int with my bigint implementations and bigint operators(add, mult) etc.,

Samuel is correct!

Thanks in advance.

For Example i can replace the above as below

static int dec2bin (char inbuf[], bigint num_convert) 
{ 
  char ctemp; 
  bigint result, power; 

  num_convert--; /* index of LS char to convert */ 
  result = 0; 
  power = 1; 
  while (num_convert >= 0) 
  { 
    ctemp = inbuf[num_convert--]; /* working digit */ 
    if (isdigit(ctemp)) 
    { 
      result = bi_add(result ,(bi_mult((ctemp-'0'), power)); 
      power = bi_mult(power , 10); 
    } 
    else 
      return(0); /* error: non-numeric digit detected */ 
  } 
  return (result); 
} 

something like this will work ?

  • 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-13T10:21:55+00:00Added an answer on May 13, 2026 at 10:21 am

    It sounds like you are looking for a solution where you do the low level arithmetic yourself.

    Have you considered using an existing bignum package such as the GNU Multi Precision Arithmetic library? It’s pretty easy to convert your existing code once you have that. For example, this code:

    result += ((ctemp-'0') * power);
    power *= 10;
    

    becomes:

    mpz_t tmp;
    mpz_init(tmp);
    mpz_mul_ui(tmp, power, ctemp - '0');
    mpz_add(result, result, tmp);
    mpz_clear(tmp);
    
    mpz_mul_ui(power, power, 10);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new to this kabeja package so please can some one provide code example
Can somebody please provide some sample code to strip diacritical marks (i.e., replace characters
Can someone please provide some example code on how I could create the following
can anybody please provide me some code that could help me. actually i am
Please provide some code example. Thanks.
e.preventDefault() is not working in my IE6. Could you please provide some code to
Please provide some good coding habits that one must follow to optimize vb.net code.
please provide me the possibility of my issue. Can we customize the push notification
Can someone please provide an example of how to store, and read xml data
Can someone please provide a simple example of how to consume a REST service

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.