Skip to content
Snippets Groups Projects
Commit dd6890a3 authored by Sandeep Mistry's avatar Sandeep Mistry
Browse files

Use modulo operator in Print::printNumber

Port of @tico-tico’s change in
https://github.com/tico-tico/Arduino/commit/a7454b6b5c59187b95c4224aad87
bb01faa06e85 to SAMD core.
parent a73e50de
No related branches found
No related tags found
No related merge requests found
......@@ -188,7 +188,8 @@ size_t Print::println(const Printable& x)
// Private Methods /////////////////////////////////////////////////////////////
size_t Print::printNumber(unsigned long n, uint8_t base) {
size_t Print::printNumber(unsigned long n, uint8_t base)
{
char buf[8 * sizeof(long) + 1]; // Assumes 8-bit chars plus zero byte.
char *str = &buf[sizeof(buf) - 1];
......@@ -198,9 +199,9 @@ size_t Print::printNumber(unsigned long n, uint8_t base) {
if (base < 2) base = 10;
do {
unsigned long m = n;
char c = n % base;
n /= base;
char c = m - base * n;
*--str = c < 10 ? c + '0' : c + 'A' - 10;
} while(n);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment