> For the complete documentation index, see [llms.txt](https://solutions.icpc.uclaacm.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://solutions.icpc.uclaacm.com/2021-tryout-solutions/tryout-1/c-bits.md).

# C: Bits

https\://open.kattis.com/problems/bits

* Firstly, we can keep successively (integer) dividing the number by $$10$$ to obtain the previous states of the calculator.
* Now, for each such number, we need to count the number of ones in the binary representation, and find the maximum value among those counts.
* This is now the classic problem of **converting a number to its binary representation**.&#x20;
  * There are builtin functions to do this! `bin(x)` in Python, `Integer.toBinaryString(x)` in Java, and `bitset<32>(x).to_string()` in C++ all give you the binary representation of the number.

{% hint style="info" %}
C++ is amazing: `__builtin_popcount(x)` directly gives you the number of ones in the binary representation of the integer `x`!
{% endhint %}
