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

◆ to_hex() [1/2]

template<typename T>
fl::enable_if< fl::is_integral< T >::value, fl::string >::type fl::printf_detail::to_hex ( T value,
bool uppercase )

Definition at line 180 of file printf.h.

180 {
181 if (value == 0) {
182 return fl::string("0");
183 }
184
186 const char* digits = uppercase ? "0123456789ABCDEF" : "0123456789abcdef";
187
188 // Handle negative values for signed types
189 bool negative = false;
190 if (fl::is_signed<T>::value && value < 0) {
191 negative = true;
192 value = -value;
193 }
194
195 while (value > 0) {
196 char ch = digits[value % 16];
197 // Convert char to string since fl::string::append treats char as number
198 char temp_ch_str[2] = {ch, '\0'};
199 fl::string digit_str(temp_ch_str);
200 // Use += since + operator is not defined for fl::string
201 fl::string temp = digit_str;
202 temp += result;
203 result = temp;
204 value /= 16;
205 }
206
207 if (negative) {
208 fl::string minus_str("-");
209 minus_str += result;
210 result = minus_str;
211 }
212
213 return result;
214}
Result type for promise operations.
static constexpr bool value

References fl::is_signed< T >::value.

Referenced by format_arg().

+ Here is the caller graph for this function: