Converts a number from decimal to binary, represented as a vector of u8
(num: u16, size: usize)
| 55 | /// Converts a number from decimal to binary, represented as a vector |
| 56 | /// of u8 |
| 57 | fn 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 | |
| 71 | type FieldName = String; |
| 72 |
no outgoing calls
no test coverage detected