Stay organized with collections
Save and categorize content based on your preferences.
strings.from_hex
strings.from_hex(hex_string)
Description
Returns the bytes associated with the given hex string.
Param data types
STRING
Return type
BYTES
Code samples
Get bytes associated with a given hex string.
Example 1
This example shows non-hex character conversions.
strings.from_hex("str") // returns empty bytes
Example 2
This example shows input with empty string.
strings.from_hex("") // returns empty bytes
Example 3
This example shows hex string conversion.
strings.from_hex("1234") // returns 1234 bytes
Example 4
This example shows non-ASCII characters conversion.
strings.from_hex("筒纸.中国") // returns empty bytes
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-06-02 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-06-02 UTC."],[[["`strings.from_hex` converts a hexadecimal string into its corresponding bytes representation, usable in Rules and Search."],["The function accepts a single string parameter (`STRING`) and returns a `BYTES` data type."],["Providing a non-hexadecimal string or an empty string to `strings.from_hex` results in empty bytes."],["Only hexadecimal strings, like `\"1234\"`, will be converted successfully to their byte values, as shown in the example."]]],[]]