I was attempting to write 128 bit integer class in C++ with the number being stored in binary format across two int64_t
. As I was trying to write the function that converts my number into an std::string
(so I can show it somewhere like in cout
) I got stuck and it raised a broader question to which I couldn't find any answer.
Consider the number 16
, in memory that number is laid down that way: 00010000
, unless I'm wrong, any occurrence of 16
in decimal form (in the code, as output values, debugger values, etc.) is in fact a string that contains two characters of values 49 (ASCII code for '1') and 54 (ASCII code for '6')
So how does the conversion from 00010000 (value in memory)
to "16" (string)
happens ?
I understand that this question sounds a bit trivial, but in my case I can't fit the numbers I want in any existing container, it would be a bit like having a 32 bit integer in binary format but no int
type, how would you print the number inside it ?