FastLED 3.9.15
Loading...
Searching...
No Matches

◆ itoa()

int fl::itoa ( i32 value,
char * buffer,
int radix )

Convert signed 32-bit integer to string buffer in given radix.

Parameters
valueThe integer value to convert
bufferOutput buffer (must be at least 34 bytes for base 2, 12 for base 10, 12 for base 16)
radixNumber base (2-36, typically 10 for decimal, 16 for hex, 8 for octal)
Returns
Number of characters written (excluding null terminator)

Definition at line 68 of file charconv.cpp.hpp.

68 {
69 char tmp[16]; // be careful with the length of the buffer
70 char *tp = tmp;
71 int i;
72 u32 v;
73
74 int sign = (radix == 10 && value < 0);
75 if (sign)
76 v = -static_cast<u32>(value);
77 else
78 v = static_cast<u32>(value);
79
80 while (v || tp == tmp) {
81 i = v % radix;
82 v = radix ? v / radix : 0;
83 if (i < 10)
84 *tp++ = i + '0';
85 else
86 *tp++ = i + 'a' - 10;
87 }
88
89 int len = tp - tmp;
90
91 if (sign) {
92 *sp++ = '-';
93 len++;
94 }
95
96 while (tp > tmp)
97 *sp++ = *--tp;
98
99 *sp = '\0'; // Null-terminate the string
100 return len;
101}
constexpr int type_rank< T >::value
constexpr enable_if< is_fixed_point< T >::value, int >::type sign(T x) FL_NOEXCEPT

References sign(), and type_rank< T >::value.

Referenced by fl::sstream::appendFormatted(), fl::basic_string::appendHex(), fl::basic_string::appendOct(), fl::ostream::operator<<(), fl::ostream::operator<<(), fl::ostream::operator<<(), fl::SerialPort::print(), fl::SerialPort::println(), fl::basic_string::write(), and fl::basic_string::write().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: