Using some tricks, you can do this quite simply. CMake expressions use int internally, so it only works up to 2 31 -1 bits. Something like this (you can change it for a big endian or something else).
function (NumberToHex number output) set (chars "0123456789abcdef") set (hex "") foreach (i RANGE 7) math (EXPR nibble "${number} & 15") string (SUBSTRING "${chars}" "${nibble}" 1 nibble_hex) string (APPEND hex "${nibble_hex}") math (EXPR number "${number} >> 4") endforeach () string (REGEX REPLACE "(.)(.)" "\\2\\1" hex "${hex}") set ("${output}" "${hex}" PARENT_SCOPE) endfunction ()
source share