> ## Documentation Index
> Fetch the complete documentation index at: https://voltaire.tevm.sh/llms.txt
> Use this file to discover all available pages before exploring further.

# Bytecode.toHex

> Convert bytecode to hex string with 0x prefix

<Card title="Try it Live" icon="play" href="https://playground.tevm.sh?example=primitives/bytecode.ts">
  Run Bytecode examples in the interactive playground
</Card>

<Tabs>
  <Tab title="C">
    ## `char* bytecode_to_hex(bytecode_t bytecode, allocator_t allocator)`

    Convert bytecode to hex string with `0x` prefix.

    **Parameters:**

    * `bytecode: bytecode_t` - Bytecode to convert
    * `allocator: allocator_t` - Allocator for result string

    **Returns:** `char*` - Hex string with `0x` prefix (must be freed by caller)

    **Example:**

    ```c theme={null}
    #include <voltaire/primitives.h>
    #include <stdlib.h>

    bytecode_t bc = bytecode_from_hex("0x6001", allocator);
    char* hex_str = bytecode_to_hex(bc, allocator);

    printf("%s\n", hex_str);  // "0x6001"

    free(hex_str);
    ```

    **Defined in:** [primitives.h](https://github.com/evmts/voltaire/blob/main/src/primitives.h)
  </Tab>
</Tabs>

## See Also

* [fromHex](/primitives/bytecode/fromhex) - Parse hex string to bytecode
