Skip to content

Instantly share code, notes, and snippets.

@muhammednagy
Created February 24, 2017 23:27
Show Gist options
  • Save muhammednagy/0f1ad3c7999c1bb4052c065e7fb40121 to your computer and use it in GitHub Desktop.
Save muhammednagy/0f1ad3c7999c1bb4052c065e7fb40121 to your computer and use it in GitHub Desktop.
count bits in erlang
-module(bitcount).
-export([bitcount/1]).
bitcount(V) ->
bitcount(V, 0).
bitcount(0, C) ->
C;
bitcount(V, C) ->
bitcount( (V band (V - 1)), (C + 1)).
@kwando
Copy link

kwando commented Dec 6, 2020

Nice 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment