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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T18:35:23+00:00 2026-06-04T18:35:23+00:00

Trying to get some code working and the modulus doesn’t want to do what

  • 0

Trying to get some code working and the modulus doesn’t want to do what I want it to do… which means I have it wrong.

I have unsigned chars that I’m trying to seperate out hours/minutes/seconds into so I can display them on the screen in Ascii.

The variable secs is anunsigned int. Everything else is anunsigned char. I want the results in unsigned chars so not to waste memory. Working in an embedded environment.

Anyone care to look at the code snippet and tell me what I’ve done wrong?

hours   = secs/3600.0;
minutes =(secs/60.0)-(hours*3600);
seconds =secs-(hours*3600)-(minutes*60);

sec_ones    =(unsigned char)((seconds%10));
sec_tens    =(unsigned char)((seconds-sec_ones)%100);
min_ones    =(unsigned char)(minutes%10);
min_tens    =(unsigned char)((minutes-min_ones)%100);
hrs_ones    =(unsigned char)(hours%10);
hrs_tens    =(unsigned char)((hours-hrs_ones)%100);
  • 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-06-04T18:35:24+00:00Added an answer on June 4, 2026 at 6:35 pm
    minutes =(secs/60.0)-(hours*3600);
    

    should be

    minutes =(secs/60.0)-(hours*60);
    

    Other than that, it works for small enough input: http://ideone.com/VPKP1

    There are some things that I’d change, though. For example, there’s no point doing a double division and then assigning the result back to unsigned char, you might as well just do integer division.

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

Sidebar

Related Questions

So I'm trying to get some tutorial code working, and I'm stuck. I have
I have some code im trying to get working. What im looking for is
Trying to get comfortable with jQuery and I have encountered some sample code that
I am trying to get some code working from an example I came across.
So I'm trying to get some basic jQuery code with Rails working, but it
I have a little sample application I was working on trying to get some
I'm trying to get some simple code working to log the pitch, roll, and
I've been trying to get some working Java code to use for encrypting Paypal
I'm trying to get some basic ajax working on rails. I have a comon
I'm trying get some licensing code from AndroidPit.com working, but I get Unable to

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.