Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

C++ ESP32 – 86400000000 is printed as 500654080

I’m working on a ESP32 using Arduino, for some reason the values are printed differently, what is the cause?

auto reset_time = 24L * 60 * 60 * 1000 * 1000; //86400000000

  Serial.print("Reset Timer in: ");
  Serial.println(reset_time);

  Serial.print((reset_time / 1000));
  Serial.println(" ms");

  Serial.print((reset_time / 1000 / 1000));
  Serial.println(" s");

  Serial.print((reset_time / 1000 / 1000 / 60));
  Serial.println(" m");

  Serial.print((reset_time / 1000 / 1000 / 60 / 60));
  Serial.println(" h");

This produces the following output:

21:05:58.310 -> Reset Timer in: 500654080
21:05:58.310 -> 500654 ms
21:05:58.310 -> 500 s
21:05:58.310 -> 8 m
21:05:58.310 -> 0 h

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

86400000000 Mod 2^32 is 500654080.

The value is larger than fits in a 32 bit int; what you see is the remainder.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading