1 #ifndef ROSE_StringUtility_NumberToString_H
2 #define ROSE_StringUtility_NumberToString_H
4 #include <Rose/BitOps.h>
7 #include <Sawyer/IntervalSet.h>
11 namespace StringUtility {
29 #if !defined(_MSC_VER) && \
30 defined(BACKEND_CXX_IS_GNU_COMPILER) && \
31 ((BACKEND_CXX_COMPILER_MAJOR_VERSION_NUMBER == 4 && BACKEND_CXX_COMPILER_MINOR_VERSION_NUMBER > 6) || \
32 BACKEND_CXX_COMPILER_MAJOR_VERSION_NUMBER > 4) && \
49 ROSE_UTIL_API std::string
intToHex(uint64_t);
60 ROSE_UTIL_API std::string
toHex2(uint64_t value,
size_t nbits,
61 bool show_unsigned_decimal=
true,
bool show_signed_decimal=
true,
62 uint64_t decimal_threshold=256);
63 ROSE_UTIL_API std::string
signedToHex2(uint64_t value,
size_t nbits);
64 ROSE_UTIL_API std::string
unsignedToHex2(uint64_t value,
size_t nbits);
66 template<
typename T> std::string
toHex(T value) {
return toHex2((uint64_t)value, 8*
sizeof(T)); }
76 ROSE_UTIL_API std::string
addrToString(uint64_t value,
size_t nbits = 0);
97 template<
typename Un
signed>
98 std::string
toBinary(Unsigned value,
size_t nBits = 0,
size_t groupSize = 4,
const std::string groupSeparator =
"_") {
102 for (
size_t i = nBits; i > 0; --i) {
104 if (groupSize > 0 && i > 1 && (i-1) % groupSize == 0)
105 retval += groupSeparator;
Holds a value or nothing.
A container holding a set of values.
ROSE_UTIL_API std::string numberToString(long long)
Convert an integer to a string.
std::string toBinary(Unsigned value, size_t nBits=0, size_t groupSize=4, const std::string groupSeparator="_")
Convert a number to a binary string.
std::string toHex(T value)
Convert a number to a hexadecimal and decimal string.
bool bit(Unsigned src, size_t i)
Extract a single bit.
ROSE_UTIL_API std::string unsignedToHex2(uint64_t value, size_t nbits)
Convert a number to a hexadecimal and decimal string.
size_t nBits(Unsigned x=Unsigned(0))
Number of bits in a type or value.
std::string signedToHex(T value)
Convert a number to a hexadecimal and decimal string.
std::string unsignedToHex(T value)
Convert a number to a hexadecimal and decimal string.
Range of values delimited by endpoints.
Main namespace for the ROSE library.
ROSE_UTIL_API std::string addrToString(uint64_t value, size_t nbits=0)
Convert a virtual address to a string.
ROSE_UTIL_API std::string signedToHex2(uint64_t value, size_t nbits)
Convert a number to a hexadecimal and decimal string.
ROSE_UTIL_API std::string intToHex(uint64_t)
Convert an integer to a hexadecimal string.
ROSE_UTIL_API std::string toHex2(uint64_t value, size_t nbits, bool show_unsigned_decimal=true, bool show_signed_decimal=true, uint64_t decimal_threshold=256)
Convert a number to a hexadecimal and decimal string.