0

how to convert a hex string to integer? Postgres way of doing this is here

Adding sample input and output tables below.

table1

+---------+
| hex_val |
+---------+
| 00ff    |
| 00b0    |
| 8000    |
| 0050    |
+---------+

output

+---------+
| int_val |
+---------+
|     255 |
|     176 |
|   32768 |
|      80 |
+---------+
Evan Carroll
  • 78,363
  • 46
  • 261
  • 468
user3206440
  • 4,749
  • 15
  • 75
  • 132

1 Answers1

1

You can use string_to_int to do this, specifying 16 as the base as the second parameter:

select string_to_int('8000',16);
 STRING_TO_INT 
---------------
         32768
(1 row)

This is documented here.

ScottMcG
  • 3,867
  • 2
  • 12
  • 21