Skip to main content

bytes_to_hex

Function bytes_to_hex 

Source
pub fn bytes_to_hex(bytes: &[u8]) -> String
Expand description

Converts a byte slice to a hexadecimal string representation.

Each byte is converted to its two-character hexadecimal representation in lowercase. This function allocates a new String on the heap.

§Parameters

  • bytes - The byte slice to convert

§Returns

A String containing the hexadecimal representation of the bytes. Each byte is represented by exactly 2 hex characters (lowercase).

§Memory Allocation

This function allocates heap memory. In memory-constrained environments, consider using bytes_to_hex_into_slice instead.

§Examples

use osal_rs::utils::bytes_to_hex;
 
let data = &[0x01, 0x23, 0xAB, 0xFF];
let hex = bytes_to_hex(data);
assert_eq!(hex, "0123abff");
 
let empty = bytes_to_hex(&[]);
assert_eq!(empty, "");