Skip to content

Commit

Permalink
Use modulo operator in Print::printNumber
Browse files Browse the repository at this point in the history
Port of @tico-tico’s change in
tico-tico@a7454b6b5c59187b95c4224aad87
bb01faa06e85 to SAM core.
  • Loading branch information
sandeepmistry committed Mar 3, 2016
1 parent 84f1628 commit b7f2796
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions hardware/arduino/sam/cores/arduino/Print.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,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];

Expand All @@ -202,9 +203,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);

Expand Down

0 comments on commit b7f2796

Please sign in to comment.