Last active
July 31, 2025 13:52
-
-
Save ChiChou/97a53caa2c0b49c1991e to your computer and use it in GitHub Desktop.
SQLite3 convert hex string to int (requires sqlite >= 3.8.3)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| WITH RECURSIVE | |
| unhex(str, val, weight) AS ( | |
| SELECT 'deadbeef', 0, 1 | |
| UNION ALL | |
| SELECT | |
| substr(str, 1, length(str) - 1), | |
| val + (instr('0123456789ABCDEF', substr(str, length(str), 1)) - 1) * weight, | |
| weight * 16 | |
| FROM unhex WHERE length(str) > 0 | |
| ) | |
| SELECT val FROM unhex order by weight desc limit 1; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It's as easy as
hexstr->>'$'using the JSON features introduced by version 3.38.0 (2022-02-22).See detailed description on Stack Overflow