Skip to main content

decode_hex

Function decode_hex 

Source
pub fn decode_hex(hex_str: &str) -> Result<Vec<u8>>
Expand description

Decodes a hexadecimal string to bytes.

§Arguments

  • hex_str - The hexadecimal string to decode (with or without “0x” prefix)

§Returns

The decoded bytes, or an error if the input is invalid.

§Errors

Returns Error::ParseError if the string contains invalid hex characters or has an odd length.

§Example

use stealth_lib::encoding::decode_hex;

let bytes = decode_hex("deadbeef").unwrap();
assert_eq!(bytes, vec![0xde, 0xad, 0xbe, 0xef]);

// Also works with 0x prefix
let bytes = decode_hex("0xdeadbeef").unwrap();
assert_eq!(bytes, vec![0xde, 0xad, 0xbe, 0xef]);