Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- using namespace std;
- void printNum(int num) {
- int cur = 128;
- for (int i = 0; i < 8; i++) {
- cout << ((num&cur) != 0 ? 1 : 0);
- cur >>= 1;
- }
- cout << endl;
- }
- int revertBit(int a) {
- int pos = 1;
- int res = 0;
- for (int i = 0; i < 8; i++) {
- int tmp = a & pos;
- if ((a&pos) != 0) {
- res |= (1 << (7 - i));
- }
- pos <<= 1;
- }
- return res;
- }
- void revert(char* text, int size) {
- ofstream out("out.txt", ios::binary);
- for (int i = size - 1; i > -1; i--) {
- out << (char) revertBit((int) text[i]);
- }
- out.close();
- }
- int main(void) {
- printNum(64 + 32 + 8 + 2);
- printNum(revertBit(64 + 32 + 8 + 2));
- ifstream in("in.txt", ios::ate | ios::binary); //поставили курсор в конец файла
- int size = in.tellg();
- char* text = new char[size];
- in.seekg(0, ios::beg); //поставили курсор в начало
- for (int i = 0; i < size; i++) {
- text[i] = in.get();
- }
- in.close();
- revert(text, size);
- system("pause");
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement