Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Why does "if ('0000' = '00e0')" return "true" when the hex. strings are unequal?

hexadecimal strings

Why does "if ('0000' = '00e0')" return "true" when the hex. strings are unequal?

by  RogerSpencer  Posted    (Edited  )
At first glance the two hex. strings appear to be unequal and normally one would expect "false". However, when the '=' operator is used for comparison, REXX first checks if both operands are numeric. '0000' is obviously numeric (zero) and '00e0' is, according to the REXX rules, also numeric and zero, it corresponds to the exponential method (mantissa.Eexponent) of writing a zero. Consequently the above comparison returns 'equal'.

If you really want to compare strings on a character-to-character basis, which is the case in this hex. comparison, use the '==' (exactly equal) operator.
Code:
if ('0000' == '00e0')...
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top