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

◆ to_hex()

template<typename T>
fl::string fl::to_hex ( T value,
bool uppercase = false,
bool pad_to_width = false )

Convert an integer value to hexadecimal string representation.

Template Parameters
TIntegral type
Parameters
valueThe integer value to convert
uppercaseIf true, use uppercase hex digits (A-F), otherwise lowercase (a-f)
pad_to_widthIf true, pad with leading zeros to full type width (default: false for minimal representation)
Returns
Hexadecimal string representation of the value

Example usage:

fl::string hex = fl::to_hex(255, false); // "ff" (minimal)
fl::string hex_upper = fl::to_hex(255, true); // "FF" (minimal uppercase)
fl::string hex_padded = fl::to_hex(255, false, true); // "000000ff" (padded to int width)
fl::string hex_neg = fl::to_hex(-16, false); // "-10"
fl::string to_hex(T value, bool uppercase=false, bool pad_to_width=false) FL_NOEXCEPT
Convert an integer value to hexadecimal string representation.
Definition string.h:517
const hex_t hex
Definition ios.cpp.hpp:6

Definition at line 517 of file string.h.

517 {
519 bool is_negative = false;
520 u64 unsigned_value;
521 if (static_cast<i64>(value) < 0 && sizeof(T) <= 8) {
522 is_negative = true;
523 unsigned_value = static_cast<u64>(-static_cast<i64>(value));
524 } else {
525 unsigned_value = static_cast<u64>(value);
526 }
527 return detail::hex(unsigned_value, width, is_negative, uppercase, pad_to_width);
528}
fl::u64 u64
Definition s16x16x4.h:221
fl::string hex(u64 value, HexIntWidth width, bool is_negative, bool uppercase, bool pad_to_width)
Internal hex conversion function (implementation in charconv.cpp)
constexpr HexIntWidth get_hex_int_width() FL_NOEXCEPT
Compile-time integer width determination (default - triggers error)
Definition charconv.h:60
constexpr int type_rank< T >::value
fl::i64 i64
Definition s16x16x4.h:222
u8 width
Definition blur.h:186
fl::u64 u64
Definition s16x16x4.h:221

References FL_NOEXCEPT, fl::detail::get_hex_int_width(), fl::detail::hex(), type_rank< T >::value, and width.

Referenced by fl::printf_detail::format_arg(), and fl::printf_detail::format_arg().

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