Skip to content

Instantly share code, notes, and snippets.

@korzo89
korzo89 / hex.cmake
Created March 5, 2017 13:11
CMake dec<->hex conversion functions
function(from_hex HEX DEC)
string(SUBSTRING "${HEX}" 2 -1 HEX)
string(TOUPPER "${HEX}" HEX)
set(_res 0)
string(LENGTH "${HEX}" _strlen)
while(_strlen GREATER 0)
math(EXPR _res "${_res} * 16")
string(SUBSTRING "${HEX}" 0 1 NIBBLE)
string(SUBSTRING "${HEX}" 1 -1 HEX)