Skip to content

Instantly share code, notes, and snippets.

@ChiChou
Last active July 31, 2025 13:52
Show Gist options
  • Select an option

  • Save ChiChou/97a53caa2c0b49c1991e to your computer and use it in GitHub Desktop.

Select an option

Save ChiChou/97a53caa2c0b49c1991e to your computer and use it in GitHub Desktop.
SQLite3 convert hex string to int (requires sqlite >= 3.8.3)
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;
@Wolf-SO
Copy link

Wolf-SO commented Jul 31, 2025

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment