From dd6890a3782b6edf880c4d7da5e46bf77b71478b Mon Sep 17 00:00:00 2001
From: Sandeep Mistry <s.mistry@arduino.cc>
Date: Thu, 3 Mar 2016 12:06:22 -0500
Subject: [PATCH] Use modulo operator in Print::printNumber
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Port of @tico-tico’s change in
https://github.com/tico-tico/Arduino/commit/a7454b6b5c59187b95c4224aad87
bb01faa06e85 to SAMD core.
---
 cores/arduino/Print.cpp | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/cores/arduino/Print.cpp b/cores/arduino/Print.cpp
index 98eb4fd6..05a1f188 100644
--- a/cores/arduino/Print.cpp
+++ b/cores/arduino/Print.cpp
@@ -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);
 
-- 
GitLab