6 releases

0.3.1 Oct 8, 2019
0.3.0 Apr 12, 2019
0.2.0 Apr 11, 2019
0.1.2 Apr 11, 2019

#760 in Database interfaces

Download history 29710/week @ 2024-07-29 26320/week @ 2024-08-05 24630/week @ 2024-08-12 25174/week @ 2024-08-19 26545/week @ 2024-08-26 23091/week @ 2024-09-02 28110/week @ 2024-09-09 27137/week @ 2024-09-16 30085/week @ 2024-09-23 31409/week @ 2024-09-30 30788/week @ 2024-10-07 32642/week @ 2024-10-14 32313/week @ 2024-10-21 32521/week @ 2024-10-28 32448/week @ 2024-11-04 24351/week @ 2024-11-11

122,348 downloads per month
Used in 10 crates (4 directly)

MIT license

7KB
100 lines

base-encode

crate docs.rs

Encode and decode data from and to any base from 2 to 256.

use base_encode::{encode, decode};

let data = vec![0x27, 0x10];
encode(&data, 10) // [1, 0, 0, 0, 0]

// leading zeros are preserved
decode(&[0, 0, 2, 5, 6], 10) // [0, 0, 1, 0]

Convert from and to strings

from_str("255", 10, b"0123456789").unwrap() // [0xff]

to_string(&[0xa], 2, b"OX").unwrap() // "XOXO"

lib.rs:

Functions for encoding data into any base from 2 to 256.

Example

use base_encode::*;

let data = vec![0x27, 0x10];
encode(&data, 10) // [1, 0, 0, 0, 0]

Leading zeros are preserved.

encode(&[0, 0, 128], 36) // [0, 0, 3, 14]
decode(&[0, 2, 5, 6], 10) // [0, 1, 0]

Encode / decode strings

from_str("255", 10, b"0123456789").unwrap() // [0xff]

to_string(&[0xa], 2, b"OX").unwrap() // "XOXO"

No runtime deps