Dec2Hex

Use this function to return the hexadecimal equivalent of an integer value.

Syntax

Dec2Hex (Value1, Digits)

Parameter

Description

Value1

This parameter specifies a integer value to be converted into a hexadecimal string value. If the parameter is not specified as an integer, it will be converted to an integer before performing the operation.

The largest hexadecimal value supported is FFFFFFFF. Keep in mind, however, that hexadecimal values are considered unsigned while integer values can be both positive and negative.

The largest integer value 2,147,483,647 is 7FFFFFFF when represented using hexadecimal. HEX values greater than 80000000 represent negative integer values. Hex value FFFFFFFF represents the integer value -1.

Digits

This parameter defaults to zero (0) and means the resulting hexadecimal value will not have leading zeros.

You can set this parameter from one (1) to eight (8) to control the minimum number of hexadecimal digits returned in the string. If you set the minimum too small to represent the value, it will be ignored.

Example

Here is an example:

y = 1000

z = Dec2Hex(y)

Result is z = 3E8

 

y = 254220

z = Dec2Hex(y,8)

Result is z = 0003E10C

 

y = -2

z = Dec2Hex(y)

Result is z = FFFFFFFE

See also