SQLite Forum

To and From Hex Conversion Methods
Login
I'm attempting to figure out how to take a 12-digit hex based string and do some maths on particular portions of it. (It's for a game, and the developers have done some HEX based %/MOD math on converting from one coordinate system to another).

If I manually enter the numbers as such:

> select printf('%0.4X',(printf('%d',0xFFF)+printf('%d',0x7FF))%0x1000)

I get the expected answer of 0x7FE.

FFF is the text i extract out of a longer string (substr(:Add12,10,3)), the 0x7FF and 0x1000 are considered constants.

How can I formulate my SQL statement to take a string based FFF and convert it to a Hex value?

The things I've tried are  
- 0x||'FFF' which fails  
- '0xFFF' which gives me 0  
- FFF gives me an invalid field  
- 'FFF' gives me 0  

I thought about just taking that 12-digit HEX string, convert it to a digit and play with ANDs and SHIFTs, but, the problem is still taking that HEX string and convert it to a number easily.