generated from PlexSheep/baserepo
fix bintolsdisplay
cargo devel CI / cargo CI (push) Successful in 1m27s
Details
cargo devel CI / cargo CI (push) Successful in 1m27s
Details
This commit is contained in:
parent
5a7f980c92
commit
97b8086624
|
@ -8,11 +8,12 @@ pub use num_traits::{PrimInt, ToPrimitive};
|
|||
/// ### Arguments
|
||||
/// * `data` - The data you are trying to dump
|
||||
pub fn bytes_to_bin(data: &[u8]) -> String {
|
||||
let mut s = format!("0b{:08b}", data.first().unwrap());
|
||||
for dat in data {
|
||||
s.push_str(&format!("_{:08b}", dat));
|
||||
if dat % 8 == 0 {
|
||||
s.push('\n')
|
||||
let mut s = String::new();
|
||||
for (i, dat) in data.iter().enumerate() {
|
||||
if i == 0 {
|
||||
s.push_str(&format!("0b{:08b}", dat));
|
||||
} else {
|
||||
s.push_str(&format!("_{:08b}", dat));
|
||||
}
|
||||
}
|
||||
s
|
||||
|
|
|
@ -6,6 +6,10 @@ fn btobin() {
|
|||
let data = [19, 19];
|
||||
let r = bytes_to_bin(&data);
|
||||
assert_eq!(r, format!("0b00010011_00010011"));
|
||||
|
||||
let data = [0xff, 0xff];
|
||||
let r = bytes_to_bin(&data);
|
||||
assert_eq!(r, format!("0b11111111_11111111"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -15,9 +19,7 @@ fn big_btobin() {
|
|||
assert_eq!(
|
||||
r,
|
||||
format!(
|
||||
"0b00001100_00011111_01010010_\
|
||||
00100000_01111011_00100000_01011100_00010111_00001100\n\
|
||||
_00100000_00001100_00000001_00000001_00000001"
|
||||
"0b00001100_00011111_01010010_00100000_01111011_00100000_01011100_00010111_00001100_00100000_00001100_00000001_00000001_00000001"
|
||||
)
|
||||
);
|
||||
}
|
||||
|
|
Reference in New Issue