Integer in hex notation?

How can I change the notation of a Integer value, t.e.:

(Integer -> hexadecimal notation)

Best reply by HmiGuide

There is another way, with the iq-text element which support the execution of JS functions.

  1. Define a Local-Script "Globals" where you can place all your global JS functions, variables and constants.
  2. Remove code, which is automatically created
  3. Insert code
    /**
    Converts an interger number to a HEX string
     * @example
     * x = Int2Hex(255, 4)); // x = "00FF"
     * 
     * @param {number} iVal Number to convert
     * @param {number} iLen length of converted string
     * @returns {string} HEX string of iVal
     */
    function Int2Hex(iVal, iLen) {
        return iVal.toString(16).toUpperCase().padStart(iLen, "0");
    }
    
    /**
     * Converts iVal into binary string
     * @example
     * x = Int2Bin(3, 4)); // x = "0011"
     *
     * @param {number} iVal Number to convert
     * @param {number} iLen length of converted string
     * @returns {string} HEX string of iVal
     */
    function Int2Bin(iVal, iLen) {
        return iVal.toString(2).padStart(iLen, "0");
    }
  4. Insert a iq-text with the INT item to display as HEX number
  5. Not working with virtual items
  6. To display Hex: Insert text: <%= Int2Hex(items[0].value,6) %>
  7. To display Bin: Insert text: <%= Int2Bin(items[0].value,6) %>
View original
3 replies