lang • hex

Hex$

String = Hex$ ( Number AS Long [ , Digits AS Integer ] )

Gets the hexadecimal representation of a number.

If Digits is specified, the representation is padded with unnecessary zeros so that Digits digits are returned.

Examples

Print Hex$(1972)
7B4
Print Hex$(1972, 8)
000007B4

The sign of a Short or Integer will be extended, because the Number will be extended to Long . If the hexadecimal representation should be limited to 16 bits the AND operator must be used.

Dim bX As Byte ' 8 bits unsigned
Dim sX As Short ' 16 Bits signed

bX = 200
sX = -456
Print Hex$(bX), Hex$(sX), Hex$(CLong(sX) And &hffff&)
C8	FFFFFFFFFFFFFE38	FE38

See also