Skip to content

Instantly share code, notes, and snippets.

@grafi-tt
Created December 26, 2019 07:39
Show Gist options
  • Save grafi-tt/b194a04108e6ab36340ea0a7b196d742 to your computer and use it in GitHub Desktop.
Save grafi-tt/b194a04108e6ab36340ea0a7b196d742 to your computer and use it in GitHub Desktop.
fn byte_to_ascii(byte: u8) -> [u8; 8] {
let diag = 0b10000000_01000000_00100000_00010000_00001000_00000100_00000010_00000001u64;
let mut byte_ascii = byte as u64 * diag;
byte_ascii &= 0x8080808080808080;
byte_ascii >>= 7;
byte_ascii += 0x3030303030303030;
byte_ascii.to_le_bytes()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment