Search code examples
sqlstringbinaryvertica

Vertica: Convert Bitstrint to integer


Is there a simple way to convert a binary string to an integer using vertica sql?

something like this:

=> SELECT bitstring_to_int('11') as temp
 temp
---
 3

I know there is bitstring_to_binary but I can't convert the binary value to an integer either.

Thanks


Solution

  • In 2023 you can convert binary to int via hex:

    SELECT hex_to_integer(to_hex(bitstring_to_binary('11')))
    

    Much shorter than the answer from 2018 (but still not perfect).