Sign Up Sign In

How to calculate the Hamming weight of a binary string?


A presently unanswered Q on Stack Overflow asks:

Does there exist a popcount function in libreoffice calc?

and clarifies that "I often use BASE(A1;2;8) to show a number in binary".

Why should this post be closed?


@Moshi Sorry, since posting this question I found out how to add tags not yet in the list and considered editing the tags more important than your suggestions. BTW I think OPs formula is not redundant - it shows the appropriate separator. ‭pnuts‭ 21 days ago

@pnuts if all you need is what format the binary string is in, then it's easy enough to say, right? You could easily give an example, such as "10110111" or something, no need to be roundabout and say that it's the result of the BASE function ‭The Enraged Codidactyl‭ 21 days ago

@Moshi No. What the OP's formula shows is use of ; (rather than ,). ‭pnuts‭ 21 days ago

@pnuts ...does that...matter? ‭The Enraged Codidactyl‭ 21 days ago

@Moshi Yes (unfortunately). Many users don't understand that the choice of separator may be optional (but critical for correct syntax). Answers have been down voted, useless edits made and users confused by mismatches. ‭pnuts‭ 21 days ago

Show 2 more comments

1 answer


I believe the answer at the moment is "No" but a very simple formula in LibreOffice can achieve the desired result:


where B1 contains:


as valid and A1 contains the number in decimal.

The B1 cell would not be required with this version:


This converts to binary, strips out the 0s and counts the number of characters left thereafter.

With the appropriate delimiter, should also work at least in Excel, Sheets and OpenOffice Calc.


Sign up to answer this question »