Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Read inputs from stdin. Write outputs to stdout.
- #include <iostream>
- #include <string>
- #include <sstream>
- using namespace std;
- int main()
- {
- string str;
- getline(cin, str);
- char p = 64; // 7th bit
- int what = ((str.c_str()[0] & p)!=0); // what is going 1st
- int howmany = 0; // how many of 'what'
- for (int n=0; n<str.length(); n++)
- {
- for (int i=0; i<7; i++)
- {
- if (((str.c_str()[n] & p)!=0) != what)
- {
- if (what==0)
- {
- cout << "00 ";
- } else
- {
- cout << "0 ";
- }
- for (int ih = 0; ih < howmany; ih++)
- {
- cout << "0";
- }
- cout << " ";
- what = (str.c_str()[n] & p)!=0;
- howmany = 1;
- }
- else
- {
- howmany++;
- }
- p = p >> 1; // move bit
- }
- p = 64; // 7th bit
- }
- if (what==0)
- {
- cout << "00 ";
- } else
- {
- cout << "0 ";
- }
- for (int ih = 0; ih < howmany; ih++)
- {
- cout << "0";
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement