MCPcopy Create free account
hub / github.com/ElementsProject/lightning / is_feature_bit_set

Function is_feature_bit_set

plugins/lsps-plugin/src/core/features.rs:38–48  ·  view source on GitHub ↗

Checks if the feature bit is set in the provided bitmap. Returns true if the `feature_bit` is set in the `bitmap`. Returns false if the `feature_bit` is unset or our ouf bounds. # Arguments `bitmap`: A slice of bytes representing the feature bitmap. `feature_bit`: The 0-based index of the bit to check across the bitmap.

(bitmap: &[u8], feature_bit: usize)

Source from the content-addressed store, hash-verified

36/// * `feature_bit`: The 0-based index of the bit to check across the bitmap.
37///
38pub fn is_feature_bit_set(bitmap: &[u8], feature_bit: usize) -> bool {
39 let byte_index = feature_bit >> 3; // Equivalent to feature_bit / 8
40 let bit_index = feature_bit & 7; // Equivalent to feature_bit % 8
41
42 if let Some(&target_byte) = bitmap.get(byte_index) {
43 let mask = 1 << bit_index;
44 (target_byte & mask) != 0
45 } else {
46 false
47 }
48}
49
50/// Returns a single feature_bit in hex representation, least-significant bit
51/// first.

Callers 1

Calls 1

getMethod · 0.45

Tested by

no test coverage detected