11 - 83 11 - 83
MELSEC-Q
11 INSTRUCTIONS AND FUNCTIONS
HEX$
Function
HEXadecimal $
• Converts a decimal number to a hexadecimal character string.
HEX$ ( <numeric expression> )
Syntax
numeric expression
• • • •
Specify within a range from -32768 to 65535.
Values from 32768 to 65535 are the same as
values from -32768 to -1 (8000
H
to FFFF
H
),
however.
Examples
PRINT HEX$(200)
• • • •
Converts 200 to C8 in hexadecimal and displays it.
Description
• The HEX$ function converts a decimal umber to a hexadecimal character string.
• The fractional part of the numeric expression is truncated, then converted into an integer.
• The hexadecimal numbers and decimal numbers correspond as follows:
Hexadecimal number
0
1
2
3
4
5
6
7
8
9
A
B
C
D
E
F
10
Decimal number
0
1
2
3
4
5
6
7
8
9
10 11 12 13 14 15 16
Program Example
10 ' Converts a decimal number to a hexadecimal number
20 A=200
:
' Defines a numeric value
30 PRINT "Decimal number=";A
40 A$=HEX$(A)
:
' Converts into a hexadecimal number
50 PRINT "Hexadecimal number=";A$
60 END
RUN
Decimal number = 200
Hexadecimal number=C8
REMARK
See the VAL, BIN$ and OCT$ functions, and Section 2.7.2.
Add "&H" before a numeric number to express a hexadecimal numeric number.
Example
Decimal
Hexadecimal
200
&HC8
Use the VAL function to convert a hexadecimal number of a character string into a
decimal number.
Example
Decimal
200
VAL( "&HC8" )
Always add "&H".