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
|
/// ### Arguments
|
||||||
/// * `data` - The data you are trying to dump
|
/// * `data` - The data you are trying to dump
|
||||||
pub fn bytes_to_bin(data: &[u8]) -> String {
|
pub fn bytes_to_bin(data: &[u8]) -> String {
|
||||||
let mut s = format!("0b{:08b}", data.first().unwrap());
|
let mut s = String::new();
|
||||||
for dat in data {
|
for (i, dat) in data.iter().enumerate() {
|
||||||
s.push_str(&format!("_{:08b}", dat));
|
if i == 0 {
|
||||||
if dat % 8 == 0 {
|
s.push_str(&format!("0b{:08b}", dat));
|
||||||
s.push('\n')
|
} else {
|
||||||
|
s.push_str(&format!("_{:08b}", dat));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
s
|
s
|
||||||
|
|
|
@ -6,6 +6,10 @@ fn btobin() {
|
||||||
let data = [19, 19];
|
let data = [19, 19];
|
||||||
let r = bytes_to_bin(&data);
|
let r = bytes_to_bin(&data);
|
||||||
assert_eq!(r, format!("0b00010011_00010011"));
|
assert_eq!(r, format!("0b00010011_00010011"));
|
||||||
|
|
||||||
|
let data = [0xff, 0xff];
|
||||||
|
let r = bytes_to_bin(&data);
|
||||||
|
assert_eq!(r, format!("0b11111111_11111111"));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -15,9 +19,7 @@ fn big_btobin() {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
r,
|
r,
|
||||||
format!(
|
format!(
|
||||||
"0b00001100_00011111_01010010_\
|
"0b00001100_00011111_01010010_00100000_01111011_00100000_01011100_00010111_00001100_00100000_00001100_00000001_00000001_00000001"
|
||||||
00100000_01111011_00100000_01011100_00010111_00001100\n\
|
|
||||||
_00100000_00001100_00000001_00000001_00000001"
|
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
Reference in New Issue