Thread: Equivalent of PHP "hex2bin()"

Equivalent of PHP "hex2bin()"

From
Stephen Cook
Date:
PHP has functions "bin2hex()" and "hex2bin()", and I have to deal with the results in PostgreSQL.

These functions "Returns an ASCII string containing the hexadecimal representation of str. The conversion is done byte-wise with the high-nibble first" and "Decodes a hexadecimally encoded binary string". Basically you can take binary data and each byte becomes two hexadecimal characters.

Is there anything in PostgreSQL that can do this already? I'm sure I can work it out but it can't hurt to ask first.

-- Stephen

Re: Equivalent of PHP "hex2bin()"

From
John McKown
Date:
to_hex() takes in integer or bigint and returns a hexadecimal string equivalent. But there is also, perhaps better, encode() and decode() which convert string to either base64, hex, or "escape" codes.


On Fri, Dec 19, 2014 at 2:38 PM, Stephen Cook <sclists@gmail.com> wrote:
PHP has functions "bin2hex()" and "hex2bin()", and I have to deal with the results in PostgreSQL.

These functions "Returns an ASCII string containing the hexadecimal representation of str. The conversion is done byte-wise with the high-nibble first" and "Decodes a hexadecimally encoded binary string". Basically you can take binary data and each byte becomes two hexadecimal characters.

Is there anything in PostgreSQL that can do this already? I'm sure I can work it out but it can't hurt to ask first.

-- Stephen



--
While a transcendent vocabulary is laudable, one must be eternally careful so that the calculated objective of communication does not become ensconced in obscurity.  In other words, eschew obfuscation.

111,111,111 x 111,111,111 = 12,345,678,987,654,321

Maranatha! <><
John McKown