Binary string comparisons

Binary string comparisons are always performed according to the binary values.

Two binary strings are equal only if the lengths of the two strings are identical. If the strings are equal up to the length of the shorter string length, the shorter string is considered less than the longer string even when the remaining bytes in the longer string are hexadecimal zeros. This is illustrated in the following table:
Table 1. Binary string comparison where one operand is longer because of hexadecimal zeros
Hexadecimal value of the first operand relationship Hexadecimal value of the second operand
X'4100' < X'410000'
X'4100' < X'42'
X'4100' = X'4100'
X'4100' > X'41'
X'4100' > X'400000'
Binary strings cannot be compared to character strings (even FOR BIT DATA) unless the character string is cast to a binary string.