Created
March 26, 2012 10:28
-
-
Save jsakamoto/2204346 to your computer and use it in GitHub Desktop.
count number of bits that type is integer. (by F#)
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
let rec numofbits bitwidth x = | |
match bitwidth with | |
|0 -> 0 | |
|_ -> (x &&& 1) + numofbits (bitwidth - 1) (x / 2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment