MCPcopy Create free account
hub / github.com/cosdata/cosdata / decimal_to_binary_vec

Function decimal_to_binary_vec

src/metadata/mod.rs:57–69  ·  view source on GitHub ↗

Converts a number from decimal to binary, represented as a vector of u8

(num: u16, size: usize)

Source from the content-addressed store, hash-verified

55/// Converts a number from decimal to binary, represented as a vector
56/// of u8
57fn decimal_to_binary_vec(num: u16, size: usize) -> Vec<u8> {
58 // Create a vector with specified size, initialized with
59 // zeros. Assuming that the binary representation of `num` will
60 // fit in `size` i.e. 2^size > num
61 let mut result = vec![0; size];
62 // Convert decimal to binary, starting from the rightmost position
63 let mut n = num;
64 for i in (0..size).rev() {
65 result[i] = (n & 1) as u8;
66 n >>= 1;
67 }
68 result
69}
70
71type FieldName = String;
72

Callers 3

query_filter_encodingFunction · 0.85
weighted_dimensionsMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected