Created
February 24, 2017 23:27
-
-
Save muhammednagy/0f1ad3c7999c1bb4052c065e7fb40121 to your computer and use it in GitHub Desktop.
count bits in erlang
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
-module(bitcount). | |
-export([bitcount/1]). | |
bitcount(V) -> | |
bitcount(V, 0). | |
bitcount(0, C) -> | |
C; | |
bitcount(V, C) -> | |
bitcount( (V band (V - 1)), (C + 1)). |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Nice 👍