Quote:By the way, you can use either QB, FB or any other language that suits your fancy .
Well, if you insist, here is a C++ version:
[syntax="C++"]#include <iostream>
#include <cstdlib>
#include <string>
#include <sstream>
using namespace std;
string charCodeToBin (int myCode);
string numToStr (int num);
int strToNum (string substring);
int main() {
string sentence, code, charCodes = "", result = "";
cout << "Enter a sentence: ";
getline(cin, sentence);
for (long letter = 0; letter < sentence.length(); letter++) {
code = numToStr((int)sentence[letter]);
for (int pad = 0; pad < 3 - code.length(); pad++)
code = '0' + code;
charCodes += code;
}
for (long asc = 0; asc < charCodes.length(); asc+=3)
result += charCodeToBin(strToNum(charCodes.substr(asc, 3)));
cout << sentence << endl << charCodes << endl << result << endl;
system("pause");
return 0;
}
string charCodeToBin (int myCode) {
string bin = "";
int n = 0;
for (int i = 0; i < 8; i++) {
n = myCode % 2;
myCode /= 2;
bin = numToStr(n) + bin;
}
return (bin + ' ');
}
string numToStr (int num) {
ostringstream buffer;
buffer << num;
return buffer.str();
}
int strToNum (string substring) {
istringstream buffer(substring);
int code;
buffer >> code;
return code;
}[/syntax]:-)
I created my own string-to-number and number-to-string functions, just for my own practice with streams. The other function is for converting the ASCII codes to binary. It could be A LOT shorter, but I figured this was the easiest and funnest to figure out (for the most part). Enjoy. :-)