Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
mohamedkhallouq
GitHub Repository: mohamedkhallouq/content
Path: blob/main/files/en-us/webassembly/reference/numeric/population_count/index.md
6516 views
---
title: Population count slug: WebAssembly/Reference/Numeric/Population_count
---

{{WebAssemblySidebar}}

The popcnt instructions, short for population count, are used to count the amount of 1s in a numbers binary representation.

{{EmbedInteractiveExample("pages/wat/popcnt.html", "tabbed-taller")}}

Syntax

;; load a number onto the stack i32.const 130 ;; 10000010 ;; count the 1s i32.popcnt ;; the top item on the stack will now be 2
InstructionBinary opcode
i32.popcnt0x69
i64.popcnt0x7b