Hex, Hex$ (functions)

Syntax

Hex[$](number)

Description

Returns a String containing the hexadecimal equivalent of number.

Comments

Hex$ returns a String, whereas Hex returns a String variant.

The returned string contains only the number of hexadecimal digits necessary to represent the number, up to a maximum of eight.

 

The number parameter can be any type but is rounded to the nearest whole number before converting to hex. If the passed number is an integer, then a maximum of four digits are returned; otherwise, up to eight digits can be returned.

The number parameter can be any expression convertible to a number. If number is Null, then Null is returned. Empty is treated as 0.

Example

This example accepts a number and displays the decimal and hexadecimal equivalent until the input number is 0 or invalid.

Sub Main()
  Do
    xs$ = InputBox("Enter a number to convert:","Hex Convert")
    x = Val(xs$)
    If x <> 0 Then
      MsgBox "Decimal: " & x & " Hex: " & Hex(x)
    Else
      MsgBox "Goodbye."
    End If
  Loop While x <> 0
End Sub

See Also

Oct, Oct$ (functions).

More information

H