I know how I would convert each string of binary seperately, but not all at once. Same thing for text. When it is converted to text my program will have no way of telling how the characters fit together.
I know how I would convert each string of binary seperately, but not all at once. Same thing for text. When it is converted to text my program will have no way of telling how the characters fit together.
My computer is awesome.
What exactly are you trying to do? I can't figure it out from your post. Are you trying to convert 0s and 1s to the appropriate ASCII values? If so, all of the ASCII values will be the same length - 8 bits.
I'm trying to convert text to binary and binary to text.
My computer is awesome.
I'd use unsigned chars and the & operator. Please excuse the sloppy code.
Code:#include <iostream> #include <cstdlib> using namespace std; int main() { int format = 0; char* raw_input = new char[100]; unsigned char* input = new unsigned char[100]; cin.getline(raw_input, 100); for(int z = 0; ; z++) { if(raw_input[z] == '\0') { input[z] = '\0'; break; } input[z] = (unsigned char)raw_input[z]; } for(int x = 0; ;x++) { if(input[x] == '\0') break; for(unsigned char y = (unsigned char)1; ; y *= (unsigned char)2) { if(input[x] & y) cout << "1"; else cout << "0"; if(y == 128) break; } cout << " "; format++; if(format > 5) { format = 0; cout << endl; } } system("PAUSE"); }
"If you tell the truth, you don't have to remember anything"
-Mark Twain
Are you talking about File I/O? i.e. Saving text in "binary" format? Or, reading an ASCII file in "binary" format? This has nothing to do with base 2, or ones & zeros.Originally Posted by cerin
Or, do you want to type an 'A', and then display "01000001"?
Text files are binary files following certain standard notations.
MagosX.com
Give a man a fish and you feed him for a day.
Teach a man to fish and you feed him for a lifetime.