Encode data into hexadecimal string.
encode-hex <data> to [ define ] <output> \
[ input-length <input length> ] \
[ output-length [ define ] <output length> ] \
[ prefix <prefix> ]
encode-hex will encode string <data> to hexadecimal string <output> given in "to" clause, which is null-terminated and consists of digits 0-9 and letters A-F. <data> can contain null-bytes and in general is any binary data, the length of which is given by <input length> in "input-length" clause. The output string <output> is allocated and its length is given in <output length> in "output-length" clause. If you wish to prefix the output with a null-terminated string <prefix>, you can specify it in "prefix" clause.
"output-length" clause is optional, and so is "prefix" (in which case no prefix is prepended). "input-length" clause is also optional, and if not specified, <input length> is taken as the string length of <data>, which is in that case assumed to be null-terminated.
Optional "define" subclause can be used to create <output> string and a number variable <output length> if they do not already exist.
Create hexadecimal string from binary data "mydata" of length 7, prefixed with string "\\\\x" (which is typically needed for PostgreSQL binary input to queries). The output string "hexout" is created and so is its length "olen" variable of type "num":
char *mydata = "\x00""A""\x00""\xF""AB""\x00""\x04";
encode-hex mydata to define hexout input-length 7 output-length define olen prefix "\\\\x"
The value of "hexout" will be:
Copyright (c) 2022 DaSoftver LLC. Vely is a trademark of Dasoftver LLC. The software and information herein are provided "AS IS" and without any warranties or guarantees of any kind. Icons copyright Paweł Kuna licensed under MIT
. This web page is licensed under CC-BY-SA-4.0