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-07-14 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-07-14 UTC."],[[["\u003cp\u003e\u003ccode\u003estrings.from_hex\u003c/code\u003e converts a hexadecimal string into its corresponding bytes representation, usable in Rules and Search.\u003c/p\u003e\n"],["\u003cp\u003eThe function accepts a single string parameter (\u003ccode\u003eSTRING\u003c/code\u003e) and returns a \u003ccode\u003eBYTES\u003c/code\u003e data type.\u003c/p\u003e\n"],["\u003cp\u003eProviding a non-hexadecimal string or an empty string to \u003ccode\u003estrings.from_hex\u003c/code\u003e results in empty bytes.\u003c/p\u003e\n"],["\u003cp\u003eOnly hexadecimal strings, like \u003ccode\u003e"1234"\u003c/code\u003e, will be converted successfully to their byte values, as shown in the example.\u003c/p\u003e\n"]]],[],null,["### strings.from_hex\n\nSupported in: \n[Rules](/chronicle/docs/detection/default-rules) [Search](/chronicle/docs/investigation/udm-search) \n\n strings.from_hex(hex_string)\n\n#### Description\n\nReturns the bytes associated with the given hex string.\n\n#### Param data types\n\n`STRING`\n\n#### Return type\n\n`BYTES`\n\n#### Code samples\n\nGet bytes associated with a given hex string.\n\n##### Example 1\n\nThis example shows non-hex character conversions. \n\n strings.from_hex(\"str\") // returns empty bytes\n\n##### Example 2\n\nThis example shows input with empty string. \n\n strings.from_hex(\"\") // returns empty bytes\n\n##### Example 3\n\nThis example shows hex string conversion. \n\n strings.from_hex(\"1234\") // returns 1234 bytes\n\n##### Example 4\n\nThis example shows non-ASCII characters conversion. \n\n strings.from_hex(\"筒纸.中国\") // returns empty bytes"]]