#digits #iterator #integer #numbers #radix

digits_iterator

Iterate over the digits of numbers in an arbitrary radix

1 unstable release

Uses old Rust 2015

0.1.0 Jun 7, 2018

#2397 in Algorithms

Download history 2534/week @ 2023-12-06 3010/week @ 2023-12-13 1251/week @ 2023-12-20 1058/week @ 2023-12-27 2432/week @ 2024-01-03 2051/week @ 2024-01-10 2084/week @ 2024-01-17 2156/week @ 2024-01-24 2297/week @ 2024-01-31 2121/week @ 2024-02-07 2314/week @ 2024-02-14 2348/week @ 2024-02-21 3023/week @ 2024-02-28 4016/week @ 2024-03-06 3331/week @ 2024-03-13 2098/week @ 2024-03-20

13,081 downloads per month
Used in 6 crates (3 directly)

Apache-2.0

11KB
242 lines

Digits Iterator

This crate adds an extension method to the integers that permits to iterate over their digits.

Note that the signed integers will be casted to the corresponding unsigned integers. Do not use this iterator with negative signed integers unless you really want to iterate over the digits of the complement.

To use this extension, add the crate and import its content:

extern crate digits_iterator;
use digits_iterator::*;

Examples

use digits_iterator::*;

let digits: Vec<_> = 2018_u32.digits().collect();
assert_eq!(digits[..], [2, 0, 1, 8]);

let digits: Vec<_> = 0b101010.digits_with_base(2).collect();
assert_eq!(digits[..], [1_u8, 0, 1, 0, 1, 0]);

lib.rs:

This crate adds an extension method to the integers that permits to iterate over their digits.

Note that the signed integers will be casted to the corresponding unsigned integers. Do not use this iterator with negative signed integers unless you really want to iterate over the digits of the complement.

To use this extension, add the crate and import its content:

extern crate digits_iterator;
use digits_iterator::*;

Examples

use digits_iterator::*;

let digits: Vec<_> = 2018_u32.digits().collect();
assert_eq!(digits[..], [2, 0, 1, 8]);

let digits: Vec<_> = 0b101010.digits_with_base(2).collect();
assert_eq!(digits[..], [1_u8, 0, 1, 0, 1, 0]);

No runtime deps