Skip to content

Extend Print class for 64bit integers. #3688

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 30, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Fix 32bit long used in long long printNumber.
  • Loading branch information
dok-net committed Feb 15, 2020
commit 6f3941801e7a7310a1e1ddd97acda4aa14ca62a5
12 changes: 6 additions & 6 deletions cores/esp32/Print.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ size_t Print::println(struct tm * timeinfo, const char * format)

size_t Print::printNumber(unsigned long n, uint8_t base)
{
char buf[8 * sizeof(long) + 1]; // Assumes 8-bit chars plus zero byte.
char buf[8 * sizeof(n) + 1]; // Assumes 8-bit chars plus zero byte.
char *str = &buf[sizeof(buf) - 1];

*str = '\0';
Expand All @@ -291,16 +291,16 @@ size_t Print::printNumber(unsigned long n, uint8_t base)
do {
char c = n % base;
n /= base;
*--str = c < 10 ? c + '0' : c + 'A' - 10;
} while(n);

*--str = c < 10 ? c + '0' : c + 'A' - 10;
} while (n);

return write(str);
}

size_t Print::printNumber(unsigned long long n, uint8_t base)
{
char buf[8 * sizeof(long long) + 1]; // Assumes 8-bit chars plus zero byte.
char buf[8 * sizeof(n) + 1]; // Assumes 8-bit chars plus zero byte.
char* str = &buf[sizeof(buf) - 1];

*str = '\0';
Expand All @@ -311,7 +311,7 @@ size_t Print::printNumber(unsigned long long n, uint8_t base)
}

do {
unsigned long m = n;
auto m = n;
n /= base;
char c = m - base * n;

Expand Down