Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fstream>
- #include "Main.h"
- #include<iostream>
- using namespace std;
- char* ChangeBits(char* b);
- int main() {
- setlocale(LC_ALL, "rus");
- ifstream file("Text.txt",ios::binary);
- ofstream fout("out.txt",ios::binary);
- if (file.is_open()) {
- //Vitya the best
- char* buffer = new char[2];
- buffer[1] = 0;
- while (!file.eof()) {
- file.read(buffer, 1);
- cout <<"считано "<< buffer << endl;
- buffer = ChangeBits(buffer);
- cout << "вставлено " << buffer << endl << endl;
- fout << buffer;
- }
- file.close();
- fout.close();
- }
- return 0;
- }
- char* ChangeBits(char *b) {
- char t = *b;
- int c = 0;
- char byte[] = { 0,0,0,0,0,0,0,0 };
- while (t) {
- char fbit = t % 2;
- t = t / 2;
- byte[c] = fbit;
- c++;
- }
- for (int i = 0; i < 8; i++) {
- cout << " " << byte[i] + 0;
- }
- t = byte[0];
- byte[0] = byte[7];
- byte[7] = t;
- cout << "\n";
- for (int i = 0; i < 8; i++) {
- cout << " " << byte[i] + 0;
- }
- cout << "\n";
- int s = 0;
- for (int i = 7; i > 0; i--) {
- s += byte[i] * pow(2, i);
- }
- *b = s;
- return b;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement