@@ -2,10 +2,24 @@
pub fn get_hex(x: u8) -> char {
- const LUTABLE: [char; 16] =
+ const LU_TABLE: [char; 16] =
['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D',
'E', 'F'];
- LUTABLE[x as usize]
+ LU_TABLE[x as usize]
+}
+
+pub fn hex_pair(x: u8) -> (char, char) {
+ (get_hex((x & 0xF0) >> 4), get_hex(x & 0x0F))
+pub fn to_line(data: &[u8]) -> String {
+ let mut out = String::new();
+ for byte in data {
+ let pair = hex_pair(*byte);
+ out.push(pair.0);
+ out.push(pair.1);
+ }
+ out
}
@@ -1,8 +1,16 @@
+use std::io::{self, Read};
pub mod hex;
fn main() {
- println!("Hello: {}", hex::get_hex(12));
+ let stdin = std::io::stdin();
+ let mut input = stdin.lock();
+ while true {
+ let mut buffer: [u8; 64] = [0; 64];
+ let read = input.read(&mut buffer);
+ println!("{}", hex::to_line(&buffer));