Conflicting data types messing up output

I am trying to split binary values into an istringstream and calculate its decimal equivalent into the total.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
void isEven(std::string op)
{
	int number;
	std::istringstream iss(op);
	int total = 0;
	int size = op.length();
	int digCount = size;
	
	iss >> number;

	for (size_t i = 0; i < size; ++i) {
	  std::cout << iss.str()[i];
     
          digCount--;

          if (iss.str()[i] != '0')
	  {		
		total += (iss.str()[i] * pow(2, digCount));
				
		std::cout << "The total is " << total << std::endl;
          }
        }
} 


When I normally output iss.str()[i] on it's own, it's either a 0 or a 1. (as intended). However, when calculating the total it seems to appear that the variable becomes a base value of 49 when [i] should always be 1 in this case. This leads to large, unnecessary totals in my program. I figure it has to do with the data type of total but I am unsure what it needs to be changed to.
std::cout << (int) '0' << ' ' << (int) '1' << '\n';
https://en.wikipedia.org/wiki/ASCII#Printable_characters

> void isEven(std::string op)
i expected for the function to return a boolean
and not sure why you are trying to reconstruct the whole number when you only want to check if it is even.
My apologies, I don't know why I went ahead and overcomplicated the matter instead of just checking the values at the ends.

Carry on.
Topic archived. No new replies allowed.