Characters to binary... binary to characters
Basically what the title says... I need to be able to convert a string to binary... then convert that to hexadecimal (cout << hex << stringname; works fine for that part, but I can't save the output), and then the ability to change hexadecimal to binary and convert the binary to the original string... basically code and decode it...
I need the part converted from the characters (it has to have letter support) to binary to be a string so it uses hexadecimal for 0 and 1, not for the letters... so the integer data type wouldn't work.
I'm using Microsoft Visual C++ 6.0 as a compiler, and this is for a console application (DOS).
ANY help would be much appreciated!
Thanks!
Almost there... one more EASY thing.
I've gotten it working just fine now, only I have one problem. If the binary value has any leading zeros, then it cuts them off because I convert it as an integer. Is there any EASY and SHORT way to add them back in, storing it as a string? I need it to have all 7 bits.
So... if the input is 'a' it typecasts so that it gets the ASCII code for it is 97, so the binary value is 110 0001. That works fine... I get 1100001 for 'a'.
But if the input is '0' for example... ASCII is 48, binary is 011 0000. It works fine but it chopps off the leading zero because it isn't a string... so what is the easiest way to get it to save 0110000 instead of 110000?
I didn't use your function.