M
Mesvak
Hi,
I have this code which takes in a file, reads it in as a binary array,
and prints the array.
Is there anyway I can write a code which would print the number of
binary values taken and printed? like a counter? So basically if a
file consists of 10529 bits... I want it to print that value also. Any
suggestions?
Code:
void dBinary(unsigned);
int main()
{
char filename[60];
cout << "Please enter the filename you wish to use to embed: \n";
cin >> filename;
ifstream in;
in.open(filename, ios::in);
char ch;
// Assign each byte to ch
// and then pass it to the function dBinary
while (in.get(ch)) {
dBinary(ch);
}
in.close();
cout << endl << endl << endl;
return 0;
}
void dBinary(unsigned u)
{
register int b;
for (b = 128; b > 0; b = b/2) {
(u & b) ? (cout << '1') : (cout << '0');
}
}
Thanks in advance for your help.
I have this code which takes in a file, reads it in as a binary array,
and prints the array.
Is there anyway I can write a code which would print the number of
binary values taken and printed? like a counter? So basically if a
file consists of 10529 bits... I want it to print that value also. Any
suggestions?
Code:
void dBinary(unsigned);
int main()
{
char filename[60];
cout << "Please enter the filename you wish to use to embed: \n";
cin >> filename;
ifstream in;
in.open(filename, ios::in);
char ch;
// Assign each byte to ch
// and then pass it to the function dBinary
while (in.get(ch)) {
dBinary(ch);
}
in.close();
cout << endl << endl << endl;
return 0;
}
void dBinary(unsigned u)
{
register int b;
for (b = 128; b > 0; b = b/2) {
(u & b) ? (cout << '1') : (cout << '0');
}
}
Thanks in advance for your help.