Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- unsigned char Xbee::readloop()
- unsigned char binary;
- string binstr;
- printf("Enter a binary number from 00000000 to 00011111 \n");
- cin >> binstr;
- while (StrErrorCheck(binstr) == true) {
- printf("Error: Please input again\n");
- cin >> binstr;
- }
- binary = bstr2dec(binstr);
- return binary;
- }
- unsigned char Xbee::bstr2dec(string str)
- {
- unsigned char result = 0;
- unsigned int i;
- for (i = 0; i < str.length(); i++) {
- result = 2 * result + (str[i] - '0');
- }
- return result;
- }
- bool Xbee::StrErrorCheck(string str) {
- bool error = false;
- unsigned int i;
- if (str.length() > 8 || str.length() == 0) {
- error = true;
- }
- for (i = 0; i < str.length(); i++) {
- if( (str[i] != '1') && (str[i] != '0') ) {
- error = true;
- }
- if( (i == 5 || i == 6 || i == 8) && (str[i] == 1) ) {
- error = true;
- }
- }
- return error;
- }
Add Comment
Please, Sign In to add comment