What is the Processing unbinary() equivalent in oF/C++?

Hi all,

What is the P5 unbinary() equivalent in oF/C++?

I found atoi() but my implementation is not working, here is the P5 code:

  
String myString = "";  
for(int k=0; k<4; k++){  
  if(vertexValues[ ref[k] ] > threshold){   
    myString = myString + "1";   
  }         
  else {   
    myString = myString + "0";   
  }  
}  
//convert on/off states in string to case number  
int lookUp = unbinary(myString);  
println( "lookUp: " + lookUp );  

And this is my oF code:

  
string mstr = "";  
for ( int k = 0; k < 4; k++ ) {  
	if ( vertexValues[ ref[k] ] > pThreshold ) {  
		mstr += "1";  
	}  
	else {  
		mstr += "0";  
	}  
}  
//cout << "mstr: " << mstr << endl;  
int lookUp = atoi( mstr.c_str() );  
cout << "lookUp: " << lookUp << endl;  

Thanks

  • rS

Ok I see why is not working, atoi() is not what I need, is there an binary to decimal conversion method in oF?

Found a solution

  
const char* binary = mstr.c_str();  
int lookUp = strtol( binary, NULL, 2 ); //atoi( mstr.c_str() );