MCPcopy Create free account
hub / github.com/BitVM/BitVM / nib_to_byte_array

Function nib_to_byte_array

bitvm/src/chunk/helpers.rs:71–90  ·  view source on GitHub ↗
(digits: &[u8])

Source from the content-addressed store, hash-verified

69 }
70
71 fn nib_to_byte_array(digits: &[u8]) -> Vec<u8> {
72 let mut msg_bytes = Vec::with_capacity(digits.len() / 2);
73
74 for nibble_pair in digits.chunks(2) {
75 let byte = (nibble_pair[0] << 4) | (nibble_pair[1] & 0b00001111);
76 msg_bytes.push(byte);
77 }
78
79 fn le_to_be_byte_array(byte_array: Vec<u8>) -> Vec<u8> {
80 assert!(
81 byte_array.len() % 4 == 0,
82 "Byte array length must be a multiple of 4"
83 );
84 byte_array
85 .chunks(4) // Process each group of 4 bytes (one u32)
86 .flat_map(|chunk| chunk.iter().rev().cloned()) // Reverse each chunk
87 .collect()
88 }
89 le_to_be_byte_array(msg_bytes)
90 }
91
92 fn replace_first_n_with_zero(hex_string: &str, n: usize) -> String {
93 let mut result = String::new();

Callers 2

extern_hash_fp_varFunction · 0.85

Calls 3

le_to_be_byte_arrayFunction · 0.85
lenMethod · 0.80
pushMethod · 0.45

Tested by

no test coverage detected