Skip to content

Instantly share code, notes, and snippets.

@Thomashrb
Created January 27, 2017 09:50
Show Gist options
  • Select an option

  • Save Thomashrb/2f6711b9d15aff69c3dc068e3167e2ae to your computer and use it in GitHub Desktop.

Select an option

Save Thomashrb/2f6711b9d15aff69c3dc068e3167e2ae to your computer and use it in GitHub Desktop.
c++ count bits lab04
//calculate
void util_heltall::beregn_data(){
antall_enere=0;
lengde=0;
pos_max_signifikant=0;
//calculate length of number
unsigned long long i = heltall;
while (i > 0){
i = i / 2;
lengde++;
}
//calculate most significant bit
//and count 1's
for (int i = 0; i< lengde; i++){
if (i%2 != 0){
antall_enere++;
}
pos_max_signifikant++;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment