Hex

Syntax:

    stringvar = Hex(number)

Command Availability:

Available on all microcontrollers

Explanation:

The Hex function will convert a number into hexadecimal format. The input number should be a byte variable, or a fixed number between 0 and 255 inclusive. After running the function, the string variable stringvar will contain a 2 digit hexadecimal number.

Example:

    'Set chip model
    #chip 16F1936

    'Set up hardware serial connection
    #define USART_BAUD_RATE 9600
    #define USART_TX_BLOCKING


    'Send EEPROM data over serial connection
    'Uses Hex to display as hexadecimal
    For CurrentLocation = 0 to 255
        'Send location
        HSerPrint Hex(CurrentLocation)
        HSerPrint ":"
        'Read byte and send
        EPRead CurrentLocation, CurrByte
        HSerPrint Hex(CurrByte)
        'Send carriage return/line feed
        HSerPrintCRLF
    Next

When using the functions Hex() do not leave space between the function call and the left brace. You will get a compiler error that is meaningless.

    ' use this, note this is no space between the Hex and the left brace!
    Hex(number_variable)
    ' do not use, note the space!
    Hex (number_variable)

See Also Str, Val