why is this code not giving me correct values for large numbers? does it have something to do with me using numbers larger than 32 bits? if so, how do i get my function to accept values of any bit size? would i just overload the function? that seems a bit of a waste of space
std::string makehex(unsigned int value, unsigned int size = 2){
std::string out;
while (value > 0){
out = h[value % 16] + out;
value /= 16;
}
while (out.size() < size)
out = "0" + out;
return out;
}
edit: usage:
std::string value = makehex(30, 5);
std::cout << value; // 0001e
Demo: http://ideone.com/v04Vo