Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Copyright (c) 2012 by Bash Vi
- // This code is released under the terms
- // of the WTFPL (What the Fuck Pulic License) version 2.0
- // http://sam.zoy.org/wtfpl/
- // Converts a string of up to 8
- // 1es and 0es to the matching (ASCII) character
- #include <bitset>
- #include <string.h>
- #include <iostream>
- #include <cstring>
- using namespace std;
- int main(int ac, char* av[])
- {
- if(strlen(av[1]) < 9)
- {
- unsigned char a;
- // put input into a string
- string str(av[1]);
- try{
- bitset<8> bs(str);
- //cout << bs.to_string() << endl; // debug statement
- memcpy(&a, &bs, 1);
- cout << a << endl;
- }
- catch (exception e)
- {
- cout << "You may only enter 1s and 0z!" << endl;
- }
- }
- else
- {
- cerr << "array too long" << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment