I am using the base64 function from here to try and run a simple program. I want to convert binary to base64 using this code:
int x = 1;
std::string data = base64_encode(reinterpret_cast<unsigned char *>((void *)&x), 4);
std::string out = base64_decode(data);
int y = reinterpret_cast<int>(out.data());
The encode function is called, and generates this string "AQAAAA=="
. From my understanding, this would should convert to 01 00 00 0
if decoded and converted to bytes (I actually don't understand why it's 7 bytes). When the decode function is called, I expect 01 00 00 00
, which would then be reinterpret_castable back into the integer 1, but rather I get "\001\000\000"
, which is not what I expect. I tried increasing the second parameter of the encode function, funnily, it gives me the proper answer of "\001\000\000\000"
after decode.