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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T12:33:38+00:00 2026-06-10T12:33:38+00:00

I have big number, time (micro seconds) stored in two 32bit variables. I need

  • 0

I have big number, time (micro seconds) stored in two 32bit variables.
I need a help, how to change micro seconds time into millisecond, so I can store result of difference in 32bit number.

More details:
I have one time in two 32bit variables. Where one variable have more significant bits and other have less significant bits. This time have microseconds resolution so I want to change it to milliseconds. So how to divide number that is stored in two variables.

  • 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-10T12:33:39+00:00Added an answer on June 10, 2026 at 12:33 pm

    If you don’t have a 64-bit type, you can do it like the following:

    uint32_t higher, lower; // your input
    
    lower /= 1000;
    lower += (higher % 1000) * 4294967L; // approximate 2^32 / 1000
    higher /= 1000;
    

    If the result fitted in lower itself, higher should be 0.

    Just note that as @Mikhail pointed out, this solution is approximate, and has an error of 0.296 * higher + 2 ms (unless I’m missing something).


    If you really want a better precision and don’t care about efficiency, you can use a bit of floating-point arithmetic in the middle, and round the results correctly. I doubt if it’s worth the effort:

    uint32_t higher, lower; // your input
    
    // simpler without a helper variable
    if (lower % 1000 >= 500)
    {
        lower /= 1000;
        ++lower;
    }
    else
        lower /= 1000;
    
    lower += round((higher % 1000) * 4294967.296); // 2^32 / 1000
    higher /= 1000;
    

    You’ll need to include <cmath> for round().

    As a note, @Mikhail’s solution in this case is probably better and may be faster. Though it’s too complex for me.


    If you have a 64-bit type, you can convert the split value to it:

    uint64_t whole_number = higher;
    whole_number <<= 32;
    whole_number |= lower;
    

    And then you can use whole_number as usual.


    Note that if you only need a difference, it will be faster to subtract the values before actually dividing.

    Assuming that you know which value is bigger:

    uint32_t higher1, lower1; // smaller value
    uint32_t higher2, lower2; // bigger value
    
    uint32_t del_high = higher2 - higher1;
    uint32_t del_low = lower2 - lower1;
    
    if (lower2 < lower1)
        --del_high;
    

    And now you can convert the result like explained before. Or with a bit luck, del_high will be 0 (if the difference is smaller than 2^32 μs), and you will have the result in del_low (in μs).

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

Sidebar

Related Questions

If have a big 'xsl:choose' chunk in which I need to set a number
I have 2 databases and I need to link information between two big tables
I have a number of tables in my database and I need help in
I have a big, complex MATLAB program. Somewhere within that, the number 0 is
I have a very big no say 'x' (10^18) and a number 'z' say
I need to find a method to read a big number of small files
I'm a happy user of Github. Over time I have accrued a number of
I have the need to find the next available number in a set: select
I started develop a distributed application and we have a big dilemma! We need
I have read that combining all of your css files into one big one,

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.