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

Function ultoa_wp

Sming/System/stringconversion.cpp:30–64  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

28}
29
30char* ultoa_wp(unsigned long val, char* buffer, unsigned int base, int width, char pad)
31{
32 char buf[40];
33 constexpr int nulpos = sizeof(buf) - 1;
34 buf[nulpos] = '\0';
35
36 // prevent crash if called with base == 1
37 if(base < 2 || base > 16) {
38 base = 10;
39 }
40
41 int i = nulpos - 1;
42 int p = 0;
43 for(; val != 0 && i != 0; --i, p++, val /= base) {
44 buf[i] = hexchar(val % base);
45 }
46 if (p == 0) {
47 buf[i--] = '0'; // case for zero
48 }
49
50 if(width != 0)
51 {
52 width -= (nulpos - i - 1);
53 if(width > 0)
54 {
55 memset(buffer, pad, width);
56 }
57 else {
58 width = 0;
59 }
60 }
61 memcpy(buffer + width, &buf[i+1], nulpos - i);
62
63 return buffer;
64}
65
66char* lltoa_wp(long long val, char* buffer, int base, int width, char pad)
67{

Callers 12

ltoa_wpFunction · 0.85
m_vsnprintfFunction · 0.85
m_printHexFunction · 0.85
ultoa_wFunction · 0.85
ultoaFunction · 0.85
printBinFunction · 0.85
ioCallbackFunction · 0.85
addMethod · 0.85
toStringMethod · 0.85
StringMethod · 0.85
concatMethod · 0.85
printNumberMethod · 0.85

Calls 1

hexcharFunction · 0.85

Tested by 2

printBinFunction · 0.68
ioCallbackFunction · 0.68