Created
January 27, 2017 09:50
-
-
Save Thomashrb/2f6711b9d15aff69c3dc068e3167e2ae to your computer and use it in GitHub Desktop.
c++ count bits lab04
This file contains hidden or 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
| //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