OK, im trying to write a c++ proggie to convert binary bits to ascii chars one that has been via proram back to a WORKING executable or whatever it was. I have found this formula from another board.....
X = "your binary char"
A = (X & 11110000 >> 4) + 65;
B = (X & 1111) + 65;
//A and B are two ASCII charaters
X= (A - 65) << 4 + (B - 65); // To go back to binary
First question is this correct. Second question if A and B are ascii chars then defining them as char should be fine right? As for the binary bit do i use .get and a char or unsigned char?? or would it be a .read and some other type??
I tried to write a quickie to run the formula and get a warning of possible loss of bits for A when a is char and X is char, ill mark that. Here is what i have, sorry its not user friendly.
Now be forgiving i am a newbie. But this does SOMETHING? but the finished product had hardly any data so i think i AM losing bits. I need to know what to define the high_bit, low_bit, and binary_bit and what read and write funcs to use. The first func MUST be pure ascii chars when done, readable in notepad ect...PHP Code:
#include<iostream.h>
#include<fstream.h>
void char_to_binary(void)
{
char binary_file[256];
char hex_file[256];
char binary_bit;
char high_bit;
char low_bit;
cout << "Input the CORRECT path to a created file: "<< endl;
cin >> binary_file;
ifstream input_file(binary_file);
cout << "Input a path and filename for the output: " << endl;
cin >> hex_file;
ofstream output_file(hex_file);
while(!input_file.eof())
{
high_bit = input_file.get();
low_bit = input_file.get();
binary_bit = (high_bit - 65) << 4 + (low_bit - 65);
output_file.put(binary_bit);
};
input_file.close();
output_file.close();
};
void binary_to_2char_bits(void)
{
char binary_file[256];
char hex_file[256];
char binary_bit;
char high_bit;
char low_bit;
cout << "Input the CORRECT path to a binary or ""any"" file i guess: "<< endl;
cin >> binary_file;
ifstream input_file(binary_file);
cout << "Input a path and filename for the output: " << endl;
cin >> hex_file;
ofstream output_file(hex_file);
while(!input_file.eof())
{
binary_bit = input_file.get();
high_bit = (binary_bit & 11110000 >> 4) + 65;
//here is warning of lost bits in conversion, also warning that object is long//
low_bit = (binary_bit & 1111) + 65;
output_file.put(high_bit);
output_file.put(low_bit);
};
input_file.close();
output_file.close();
};
void main(void)
{
binary_to_2char_bits();
cout << "first convert done..." << endl;
char_to_binary();
cout << "Program done.";
};
Also I am confused in the formula. I understand what its doing and the bitwise and operator but i am not understanding what the redirection " >> 4" is doing there. If someone could tell me that too.
I know its alot in one post but its late and i am tired and anxious to get this to work as its the last part of my programs functionallity. Thanks alot ill chack back in less than 24hours.