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.
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