user3206440
user3206440

Reputation: 5059

hex string to integer

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 |
+---------+

Upvotes: 0

Views: 4707

Answers (1)

ScottMcG
ScottMcG

Reputation: 3887

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.

Upvotes: 1

Related Questions