Is it possible to convert CString to Binary

I have this program where I am storing data, which are binary values, into a CString variable. Once I am done storing all data into CString I want to convert it to a binary and than to a int. With this in mind, I want to know if it is possible to convert a CString variable to binary? I tried to just convert the string to int, thinking it would give me the correct value but it didn't. For example, I have the following:
1
2
3
4
CString input = "";
input = "00011"//binary form so int value should be 3
int num = atoi(input)//returned 11 instead of 3


Any help will be greatly appreciated!!!!!
You may have to write your own function for this. something like this

1
2
3
4
5
6
7
8
9
10
char arr[] = "11000";
int output = 0;
int index = 0;
	
while(arr[index] != 0)
{
		
	output |= (arr[index] - '0') << index;
	index++; 
}
Under Unix, use strtol() with a base of 2.
Actually the function strtol() is in the standard libraries, so it is on every platform :)
http://cplusplus.com/reference/clibrary/cstdlib/strtol/
You start by initializing the variable input with ="" which is unnecessary.
Also is there a primitive type 'CString' in C?
Topic archived. No new replies allowed.