Last active
November 10, 2017 04:27
-
-
Save ShXck/bd92612e6b7e2fd0ed9939a7660124fe to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Conviertan el binario a string así: | |
int binary_int = 10100110; | |
std::string bin_str = std::to_string( binary_int ); | |
// cuenten los 1 o 0 no se | |
int counter = 0; | |
for( int i = 0; i < bin_str.lenght(); i++ ) { | |
int _integer = std::stoi( bin_str[0] ); | |
if( _integer == 1 ) { // o 0 | |
counter++; | |
} | |
// una vez contada agregen el bit ese al final | |
bin_str += "1" // o 0. | |
// y luego lo convierten a integer otra vez | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment