Logic gate doesn't seem to behave logically

Well yes except "49" < "7" etc.