| Crates.io | calcbits |
| lib.rs | calcbits |
| version | 0.1.1 |
| created_at | 2025-09-13 08:03:16.216742+00 |
| updated_at | 2025-09-13 09:43:23.06504+00 |
| description | Small utilities for working with downloaded binary data: formatting, timing and CLI progress helpers. |
| homepage | |
| repository | https://github.com/Kazan20/calcbits |
| max_upload_size | |
| id | 1837420 |
| size | 53,276 |
calcbits is a Rust library for bit-level calculations and analysis.
It provides simple and efficient utilities to manipulate, inspect, and compute values at the bit level.
Add calcbits to your project with Cargo:
[dependencies]
calcbits = "0.1.0"
Then import it in your code:
use calcbits::bits;
use calcbits::bits;
fn main() {
let n: u32 = 0b101101;
// Count set bits
let count = bits::count_ones(n);
println!("Set bits: {}", count); // → 4
// Count unset bits
let zeros = bits::count_zeros(n);
println!("Unset bits: {}", zeros);
// Convert to binary string
println!("Binary: {}", bits::to_binary_string(n, 8)); // → "00101101"
// Bit masking
let masked = bits::mask(n, 0b1111);
println!("Masked: {:b}", masked); // → "1101"
}
count_ones(x) → number of set bits in xcount_zeros(x) → number of unset bits in xto_binary_string(x, width) → binary representation padded to widthmask(x, mask) → apply a maskClone the repo and run tests:
git clone https://github.com/yourname/calcbits
cd calcbits
cargo test
Licensed under either of:
Made with ❤️ in Rust.