function(to_hex HEX)
+ # mind you, not really hexadecimal, but just a decimal in hex notation, huh?!
set(XNUMBER 0x)
- set(XDIGITS 0 1 2 3 4 5 6 7 8 9 a b c d e f)
foreach(DEC IN LISTS ARGN)
- if(${DEC} GREATER 255)
- message(WARNING "to_hex(HEX ${DEC}): decimal number out of uint8 range (>=256)")
+ while(1)
+ string(LENGTH "${DEC}" LEN)
+ if(LEN GREATER_EQUAL 3)
+ break()
+ endif()
+ string(CONCAT DEC "0" "${DEC}")
+ endwhile()
+ if(DEC GREATER 999)
+ message(WARNING "to_hex(HEX ${DEC}): decimal wider than 3 digits")
endif()
- math(EXPR HIDEC "${DEC} / 16")
- math(EXPR LODEC "${DEC} % 16")
- list(GET XDIGITS ${HIDEC} HIHEX)
- list(GET XDIGITS ${LODEC} LOHEX)
- string(APPEND XNUMBER ${HIHEX}${LOHEX})
+ string(APPEND XNUMBER ${DEC})
endforeach()
set(${HEX} ${XNUMBER} PARENT_SCOPE)
endfunction()