Skip to content

Glossary: Algorithms Beyond the Basics in Rust

Bit methods (count_ones, from_str_radix)

Also written: count_ones(), count_ones, from_str_radix, u32::from_str_radix

`n.count_ones()` counts the 1 bits in a number, such as how many options an order has switched on. `from_str_radix("1101", 2)` reads text written in a given base and returns a `Result` because the text might not be valid.

Where the book teaches it

Related terms

Bitmask / flagBinary / bit