Skip to content

Commit dd6890a

Browse files
committed
Use modulo operator in Print::printNumber
Port of @tico-tico’s change in tico-tico/Arduino@a7454b6b5c59187b95c4224aad87 bb01faa06e85 to SAMD core.
1 parent a73e50d commit dd6890a

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

cores/arduino/Print.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,8 @@ size_t Print::println(const Printable& x)
188188

189189
// Private Methods /////////////////////////////////////////////////////////////
190190

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

@@ -198,9 +199,9 @@ size_t Print::printNumber(unsigned long n, uint8_t base) {
198199
if (base < 2) base = 10;
199200

200201
do {
201-
unsigned long m = n;
202+
char c = n % base;
202203
n /= base;
203-
char c = m - base * n;
204+
204205
*--str = c < 10 ? c + '0' : c + 'A' - 10;
205206
} while(n);
206207

0 commit comments

Comments
 (0)