MCPcopy Create free account
hub / github.com/VerySleepy/verysleepy / toHexString

Function toHexString

src/utils/stringutils.cpp:149–184  ·  view source on GitHub ↗

for 64 bit integers NOTE: this function is unchanged from the 32 bit version... so turn into template? or could cast 32 bit ints into 64 bit ints and always use this version.

Source from the content-addressed store, hash-verified

147//NOTE: this function is unchanged from the 32 bit version... so turn into template?
148//or could cast 32 bit ints into 64 bit ints and always use this version.
149const std::wstring toHexString(unsigned long long i)
150{
151 assert(sizeof(unsigned long long) == 8);
152
153 //------------------------------------------------------------------------
154 //build the hex string in reverse order
155 //------------------------------------------------------------------------
156 std::wstring reverse_s;
157 unsigned long long nibble;
158
159 while(i != 0)
160 {
161 nibble = i & 0x000000000000000F;//get last 4 bits
162 if(nibble <= 9)
163 reverse_s.push_back('0' + (char)nibble - 0);
164 else
165 reverse_s.push_back('a' + (char)nibble - 10);
166
167 i >>= 4;//shift right 4 bits
168 }
169
170 if(reverse_s.empty())
171 {
172 //hex constants must have at least one digit :)
173 return L"0x0";
174 }
175 else
176 {
177 std::wstring s;
178 s.resize(reverse_s.size());
179 for(unsigned int z=0; z<s.size(); ++z)
180 s[z] = reverse_s[reverse_s.size() - z - 1];
181
182 return L"0x" + s;
183 }
184}
185
186const std::wstring intToString(int i)
187{

Callers 3

displayListMethod · 0.85
CallstackView.cppFile · 0.85
saveDataMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected