File tree Expand file tree Collapse file tree 2 files changed +65
-0
lines changed Expand file tree Collapse file tree 2 files changed +65
-0
lines changed Original file line number Diff line number Diff line change @@ -255,3 +255,56 @@ size_t Print::printFloat(double number, uint8_t digits)
255255
256256 return n;
257257}
258+
259+ #ifdef SUPPORT_LONGLONG
260+
261+ void Print::println (int64_t n, uint8_t base)
262+ {
263+ print (n, base);
264+ println ();
265+ }
266+
267+ void Print::print (int64_t n, uint8_t base)
268+ {
269+ if (n < 0 )
270+ {
271+ print ((char )' -' );
272+ n = -n;
273+ }
274+ if (base < 2 ) base = 2 ;
275+ print ((uint64_t )n, base);
276+ }
277+
278+ void Print::println (uint64_t n, uint8_t base)
279+ {
280+ print (n, base);
281+ println ();
282+ }
283+
284+ void Print::print (uint64_t n, uint8_t base)
285+ {
286+ if (base < 2 ) base = 2 ;
287+ printLLNumber (n, base);
288+ }
289+
290+ void Print::printLLNumber (uint64_t n, uint8_t base)
291+ {
292+ unsigned char buf[16 * sizeof (long )];
293+ unsigned int i = 0 ;
294+
295+ if (n == 0 )
296+ {
297+ print ((char )' 0' );
298+ return ;
299+ }
300+
301+ while (n > 0 )
302+ {
303+ buf[i++] = n % base;
304+ n /= base;
305+ }
306+
307+ for (; i > 0 ; i--)
308+ print ((char ) (buf[i - 1 ] < 10 ? ' 0' + buf[i - 1 ] : ' A' + buf[i - 1 ] - 10 ));
309+ }
310+ #endif
Original file line number Diff line number Diff line change 3131#define OCT 8
3232#define BIN 2
3333
34+ // uncomment next line to support printing of 64 bit ints.
35+ #define SUPPORT_LONGLONG
36+
3437class Print
3538{
3639 private:
3740 int write_error;
3841 size_t printNumber (unsigned long , uint8_t );
42+ #ifdef SUPPORT_LONGLONG
43+ void printLLNumber (uint64_t , uint8_t );
44+ #endif
3945 size_t printFloat (double , uint8_t );
4046 protected:
4147 void setWriteError (int err = 1 ) { write_error = err; }
@@ -79,6 +85,12 @@ class Print
7985 size_t println (double , int = 2 );
8086 size_t println (const Printable&);
8187 size_t println (void );
88+ #ifdef SUPPORT_LONGLONG
89+ void println (int64_t , uint8_t = DEC);
90+ void print (int64_t , uint8_t = DEC);
91+ void println (uint64_t , uint8_t = DEC);
92+ void print (uint64_t , uint8_t = DEC);
93+ #endif
8294};
8395
8496#endif
You can’t perform that action at this time.
0 commit comments