Help converting binary!

Hey guys, I'm wondering why this code wont convert to characters? It keeps coming up that it is invalid binary even though it is correct? When letters or non numbers that are 0 or 1 are pressed it accepts, but has no output? Thank you!
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
  int bin_to_ascii(){
        string wordtwo;
        char ch;
        cout<<"Type in binary that you would like converted to ascii!"<< endl;
        getline(cin, wordtwo);
                for (int x = 0; x < wordtwo.length() / 8; ++x)
                {
                        int conv = 0;
                                for(int y = 0; y < 8; y++)
                                        {
                                        char ch = wordtwo.at(x*8+y);
                                        if(ch == '1')
                                                conv += 1 < (7-y);
                                        else if(ch != '0');
                                        }
                                        {
                                                cout<<"  " << ch <<"Input valid binary!"<<endl;
                                        }
                                        cout<< static_cast<char>(conv);
                }
                                cout<< "   " << endl;
        return 0;
}
Last edited on
Topic archived. No new replies allowed.