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 1059765
In Process

The Archive Base Latest Questions

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

Using a microcontroller (PIC18F4580), I need to collect data and send it to an

  • 0

Using a microcontroller (PIC18F4580), I need to collect data and send it to an SD card for later analysis. The data it collects will have values between 0 and 1023, or 0x0 and 0x3FF.

So what I need to do is convert 1023 into a base 10 string of literal ASCII values (0x31, 0x30, 0x32, 0x33, …).

My problem is that the only way I can think of to split the digits apart requires a lot of division.

char temp[4];
temp[0] = 1023 % 10;
temp[1] = (1023 % 100) / 10;
temp[2] = (1023 % 1000) / 100;
temp[3] = (1023 % 10000) / 1000;

Using this method, finding the ASCII values of an n digit decimal number requires 2n-1 divisions. Is there a method that would be faster?

The end goal of this is to wind up with a .csv file on the SD card that can quickly be plugged into any laptop to see a graph of the data in Excel.

  • 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-16T18:13:25+00:00Added an answer on May 16, 2026 at 6:13 pm

    There’s a way of doing it using subtractions, but I am not convinced it’s faster than using subtractions and modulus on a "normal" CPU (may be different in an embedded environment).

    Something like this:

    char makedigit (int *number, int base)
    {
      static char map[] = "0123456789";
      int ix;
    
      for (ix=0; *number >= base; ix++) { *number -= base; }
    
      return map[ix];
    }
    
    
    char *makestring (int number)
    {
      static char tmp[5];
    
      tmp[0] = makedigit(&number, 1000);
      tmp[1] = makedigit(&number, 100);
      tmp[2] = makedigit(&number, 10);
      tmp[3] = makedigit(&number, 1);
      tmp[4] = '\0';
    
      return tmp;
    }
    

    Then, a call to makestring() should result in a (static, so copy it before overwriting) string with the converted number (zero-prefixed, at 4 characters width, as the original assumption is a value in the 0-1023 range).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i need to send and receive data to/from a microcontroller using java using usb
I have to make a hardware project using a microcontroller, memory, screens, etc. Is
hi I'm programming a microcontroller using MikroC, and I have this variable which is
I have an Arduino microcontroller listening on COM3. Using the arduino IDE and the
I am using a microcontroller with a C51 core. I have a fairly timeconsuming
I have a watchdog in my microcontroller that if it is not kicked, will
I'm working in an embedded microcontroller and I have to read/write multiple types data
I want to send temperature value from a microcontroller using UART to C# interface
I am using Ubunt 10.10. I want to communicate with a microcontroller (ATmega328p) using
Are there any PIC microcontroller programmers here? I'm learning some PIC microcontroller programming using

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.