CCC Docs
    Preparing search index...

    Function bytesLenUnsafe

    • Fast byte length for Hex strings.

      This function efficiently calculates the byte length of Hex values:

      • Skips isHex validation (caller must ensure input is valid Hex)
      • Handles odd-digit hex by rounding up, matching bytesFrom's padding behavior.

      Parameters

      • hex: `0x${string}`

        A valid Hex string (with "0x" prefix).

      Returns number

      Byte length of the hex string.

      bytesLenUnsafe("0x48656c6c6f") // 5
      bytesLenUnsafe("0x123") // 2 (odd digits round up via padding)

      bytesLen - Validated version for untrusted input