Hey guys I'm having an extremely hard time splitting or combining values into binary..
#define Chr(n) ((char)(n))
#define Ord(c) ((int)(unsigned char)(c))
int DecToBin(int Num)
{
int Bin = 0, Pos = 1;
while (Num > 0)
{
Bin += (Num % 2) * Pos;
Num /= 2;
Pos *= 10;
}
return Bin;
}
int ConcatIntegers(IntegerArray Integers)
{
stringstream SS;
for (unsigned short I = 0; I < Integers.size(); I++)
{
SS<<Integers[I];
}
assert(SS.str().size() <= 10);
return strtol(SS.str().c_str(), NULL, 10);
}
string EncodeB64(string StringToEncode)
{
size_t STE_Size = StringToEncode.size();
IntegerArray Binaries; //Custom time.. just a vector of ints
for (unsigned short I = 0; I < STE_Size; I++)
Binaries(DecToBin(Ord(StringToEncode[I])));
//Binaries now holds an array of Binary Integers..
//Example.. Binaries looks like: [10101011, 101010011, 10010101...]
//For each letter in the string..
}
I've been following: http://www.cpp-home.com/tutorials/102_1.htm
And it says Convert each character in the string to binary.. which I did above. Then it says to connect all the characters into one.. That is a problem for me because if it's an entire sentence, an integer isn't large enough to hold even 3 sets of those..
Example.. I'm trying to do the above into: 1010101110101001110010101... using ConcatIntegers function but it overflows.. I'm thinking of making it all into a string and then splitting it into 6 like the tutorial says and then convert each one back to an ASCII character and continue from there but that's quite tedious..
Any better Ideas? I do not want any copyright stuff.. I wanted to write my own so I learn something AND I won't have to copy anyone else's..