# rune-hex
> Hex encoding and decoding for byte slices and files.
[](https://crates.io/crates/rune-hex)
[](https://docs.rs/rune-hex)
[](LICENSE)
[](https://github.com/alexile/runes/actions)
Converts between raw bytes and hexadecimal strings. Decoding accepts lowercase,
uppercase, mixed-case, and optional `0x` prefix. The library has zero dependencies.
## Installation
```toml
[dependencies]
rune-hex = "0.1"
```
## CLI
```bash
cargo install rune-hex
```
## Usage
### Library
```rust
use rune_hex::{encode, encode_upper, decode};
assert_eq!(encode(b"\xde\xad\xbe\xef"), "deadbeef");
assert_eq!(encode_upper(b"\xde\xad\xbe\xef"), "DEADBEEF");
assert_eq!(decode("deadbeef").unwrap(), b"\xde\xad\xbe\xef");
assert_eq!(decode("DEADBEEF").unwrap(), b"\xde\xad\xbe\xef");
assert_eq!(decode("0xDeAdBeEf").unwrap(), b"\xde\xad\xbe\xef");
```
### CLI
```bash
# Encode a file
rune-hex encode firmware.bin
# Encode stdin
# Uppercase output
# Decode hex to raw bytes
rune-hex decode deadbeef > out.bin
# Decode from stdin
# Decode with 0x prefix
rune-hex decode 0xdeadbeef > out.bin
```
## License
MIT