mirror of
https://github.com/arduino/Arduino.git
synced 2025-02-21 15:54:39 +01:00
Use modulo operator in Print::printNumber
Port of @tico-tico’s change in https://github.com/tico-tico/Arduino/commit/a7454b6b5c59187b95c4224aad87 bb01faa06e85 to SAM core.
This commit is contained in:
parent
84f16283bb
commit
b7f279610b
@ -192,7 +192,8 @@ size_t Print::println(const Printable& x)
|
|||||||
|
|
||||||
// Private Methods /////////////////////////////////////////////////////////////
|
// 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 buf[8 * sizeof(long) + 1]; // Assumes 8-bit chars plus zero byte.
|
||||||
char *str = &buf[sizeof(buf) - 1];
|
char *str = &buf[sizeof(buf) - 1];
|
||||||
|
|
||||||
@ -202,9 +203,9 @@ size_t Print::printNumber(unsigned long n, uint8_t base) {
|
|||||||
if (base < 2) base = 10;
|
if (base < 2) base = 10;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
unsigned long m = n;
|
char c = n % base;
|
||||||
n /= base;
|
n /= base;
|
||||||
char c = m - base * n;
|
|
||||||
*--str = c < 10 ? c + '0' : c + 'A' - 10;
|
*--str = c < 10 ? c + '0' : c + 'A' - 10;
|
||||||
} while(n);
|
} while(n);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user