MCPcopy Create free account
hub / github.com/SmingHub/Sming / ulltoa_wp

Function ulltoa_wp

Sming/System/stringconversion.cpp:77–111  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

75}
76
77char* ulltoa_wp(unsigned long long val, char* buffer, unsigned int base, int width, char pad)
78{
79 char buf[80];
80 constexpr int nulpos = sizeof(buf) - 1;
81 buf[nulpos] = '\0';
82
83 // prevent crash if called with base == 1
84 if(base < 2) {
85 base = 10;
86 }
87
88 int i = nulpos - 1;
89 int p = 0;
90 for(; val != 0 && i != 0; --i, p++, val /= base) {
91 buf[i] = hexchar(val % base);
92 }
93 if (p == 0) {
94 buf[i--] = '0'; // case for zero
95 }
96
97 if(width != 0)
98 {
99 width -= (nulpos - i - 1);
100 if(width > 0)
101 {
102 memset(buffer, pad, width);
103 }
104 else {
105 width = 0;
106 }
107 }
108 memcpy(buffer + width, &buf[i+1], nulpos - i);
109
110 return buffer;
111}
112
113// Author zitron: http://forum.arduino.cc/index.php?topic=37391#msg276209
114// modified by ADiea: remove dependencies strcat, floor, round; reorganize+speedup code

Callers 7

lltoa_wpFunction · 0.85
m_vsnprintfFunction · 0.85
ulltoa_wFunction · 0.85
ulltoaFunction · 0.85
StringMethod · 0.85
concatMethod · 0.85
printNumberMethod · 0.85

Calls 1

hexcharFunction · 0.85

Tested by

no test coverage detected