Skip to content

Commit b7f2796

Browse files
committed
Use modulo operator in Print::printNumber
Port of @tico-tico’s change in tico-tico@a7454b6b5c59187b95c4224aad87 bb01faa06e85 to SAM core.
1 parent 84f1628 commit b7f2796

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

hardware/arduino/sam/cores/arduino/Print.cpp

+4-3
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,8 @@ size_t Print::println(const Printable& x)
192192

193193
// Private Methods /////////////////////////////////////////////////////////////
194194

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

@@ -202,9 +203,9 @@ size_t Print::printNumber(unsigned long n, uint8_t base) {
202203
if (base < 2) base = 10;
203204

204205
do {
205-
unsigned long m = n;
206+
char c = n % base;
206207
n /= base;
207-
char c = m - base * n;
208+
208209
*--str = c < 10 ? c + '0' : c + 'A' - 10;
209210
} while(n);
210211

0 commit comments

Comments
 (0)