SHARE
TWEET

Untitled

a guest Nov 22nd, 2019 99 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <fstream>
  2. #include "Main.h"
  3. #include<iostream>
  4. using namespace std;
  5. char* ChangeBits(char* b);
  6. int main() {
  7.     setlocale(LC_ALL, "rus");
  8.     ifstream file("Text.txt",ios::binary);
  9.     ofstream fout("out.txt",ios::binary);
  10.     if (file.is_open()) {
  11.         //Vitya the best
  12.         char* buffer = new char[2];
  13.         buffer[1] = 0;
  14.        
  15.         while (!file.eof()) {
  16.             file.read(buffer, 1);
  17.             cout <<"считано "<< buffer << endl;
  18.             buffer = ChangeBits(buffer);
  19.             cout << "вставлено " << buffer << endl << endl;
  20.             fout << buffer;
  21.         }
  22.         file.close();
  23.         fout.close();
  24.     }
  25.         return 0;
  26. }
  27.  
  28. char* ChangeBits(char *b) {
  29.     char t = *b;
  30.     int c = 0;
  31.     char byte[] = { 0,0,0,0,0,0,0,0 };
  32.     while (t) {
  33.         char fbit = t % 2;
  34.         t = t / 2;
  35.         byte[c] = fbit;
  36.         c++;
  37.     }
  38.     for (int i = 0; i < 8; i++) {
  39.         cout << " " << byte[i] + 0;
  40.     }
  41.     t = byte[0];
  42.     byte[0] = byte[7];
  43.     byte[7] = t;
  44.     cout << "\n";
  45.     for (int i = 0; i < 8; i++) {
  46.         cout << " " << byte[i] + 0;
  47.     }
  48.     cout << "\n";
  49.     int s = 0;
  50.     for (int i = 7; i > 0; i--) {
  51.         s += byte[i] * pow(2, i);
  52.     }
  53.     *b = s;
  54.     return b;
  55. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top