What do the logical functions IMP and EQV do in VB6? Has anyone found a real world use for them?

放肆的年华 提交于 2019-12-06 20:55:21

问题


And, Or, Xor and Not I understand. What I don't get are Imp and Eqv. What do they mean? How'd they get in there? Is there any real use for them?


回答1:


IMP is "material implication" "a implies b" or "if a then b", which is equivalent to NOT a OR b. EQV is "equivalence" or "if and only if", so a EQV b is the same as (a IMP b) AND (b IMP a).

They got there because someone wanted to be complete. They can shorten some logical expressions, but you can always express the same thing with NOT and AND, NOT and OR, or with XOR alone.




回答2:


Here is the truth table for all the operators, both for boolean and for bitwise. The best time to use them is when you map your logic and realize you have a function that takes two inputs, and has the same outputs as those operators:)

------------------------------------------------------------------------------------------------------------------
|AND  |     |     |     |OR   |     |     |     |XOR  |     |     |     |IMP  |     |     |     |EQV  |     |     |
------------------------------------------------------------------------------------------------------------------
|In1  |In2  |Out1 |     |In1  |In2  |Out1 |     |In1  |In2  |Out1 |     |In1  |In2  |Out1 |     |In1  |In2  |Out1 |
------------------------------------------------------------------------------------------------------------------
|False|False|False|     |False|False|False|     |False|False|False|     |False|False|True |     |False|False|True |
------------------------------------------------------------------------------------------------------------------
|False|True |False|     |False|True |True |     |False|True |True |     |False|True |True |     |False|True |False|
------------------------------------------------------------------------------------------------------------------
|False|Null |False|     |False|Null |Null |     |False|Null |Null |     |False|Null |True |     |False|Null |Null |
------------------------------------------------------------------------------------------------------------------
|True |False|False|     |True |False|True |     |True |False|True |     |True |False|False|     |True |False|False|
------------------------------------------------------------------------------------------------------------------
|True |True |True |     |True |True |True |     |True |True |False|     |True |True |True |     |True |True |True |
------------------------------------------------------------------------------------------------------------------
|True |Null |Null |     |True |Null |True |     |True |Null |Null |     |True |Null |Null |     |True |Null |Null |
------------------------------------------------------------------------------------------------------------------
|Null |False|False|     |Null |False|Null |     |Null |False|Null |     |Null |False|Null |     |Null |False|Null |
------------------------------------------------------------------------------------------------------------------
|Null |True |Null |     |Null |True |True |     |Null |True |Null |     |Null |True |True |     |Null |True |Null |
------------------------------------------------------------------------------------------------------------------
|Null |Null |Null |     |Null |Null |Null |     |Null |Null |Null |     |Null |Null |Null |     |Null |Null |Null |
------------------------------------------------------------------------------------------------------------------
|     |     |     |     |     |     |     |     |     |     |     |     |     |     |     |     |     |     |     |
------------------------------------------------------------------------------------------------------------------
|In1  |In2  |Out1 |     |In1  |In2  |Out1 |     |In1  |In2  |Out1 |     |In1  |In2  |Out1 |     |In1  |In2  |Out1 |
------------------------------------------------------------------------------------------------------------------
|001  |001  |001  |     |001  |001  |001  |     |001  |001  |000  |     |001  |001  |111  |     |001  |001  |111  |
------------------------------------------------------------------------------------------------------------------
|001  |010  |000  |     |001  |010  |011  |     |001  |010  |011  |     |001  |010  |110  |     |001  |010  |100  |
------------------------------------------------------------------------------------------------------------------
|001  |011  |001  |     |001  |011  |011  |     |001  |011  |010  |     |001  |011  |111  |     |001  |011  |101  |
------------------------------------------------------------------------------------------------------------------
|001  |100  |000  |     |001  |100  |101  |     |001  |100  |101  |     |001  |100  |110  |     |001  |100  |010  |
------------------------------------------------------------------------------------------------------------------
|010  |001  |000  |     |010  |001  |011  |     |010  |001  |011  |     |010  |001  |101  |     |010  |001  |100  |
------------------------------------------------------------------------------------------------------------------
|010  |010  |010  |     |010  |010  |010  |     |010  |010  |000  |     |010  |010  |111  |     |010  |010  |111  |
------------------------------------------------------------------------------------------------------------------
|010  |011  |010  |     |010  |011  |011  |     |010  |011  |001  |     |010  |011  |111  |     |010  |011  |110  |
------------------------------------------------------------------------------------------------------------------
|010  |100  |000  |     |010  |100  |110  |     |010  |100  |110  |     |010  |100  |101  |     |010  |100  |001  |
------------------------------------------------------------------------------------------------------------------
|011  |001  |001  |     |011  |001  |011  |     |011  |001  |010  |     |011  |001  |101  |     |011  |001  |101  |
------------------------------------------------------------------------------------------------------------------
|011  |010  |010  |     |011  |010  |011  |     |011  |010  |001  |     |011  |010  |110  |     |011  |010  |110  |
------------------------------------------------------------------------------------------------------------------
|011  |011  |011  |     |011  |011  |011  |     |011  |011  |000  |     |011  |011  |111  |     |011  |011  |111  |
------------------------------------------------------------------------------------------------------------------
|011  |100  |000  |     |011  |100  |111  |     |011  |100  |111  |     |011  |100  |100  |     |011  |100  |000  |
------------------------------------------------------------------------------------------------------------------



回答3:


IIRC, they both perform a bitwise !XOR on the two inputs and return the result.

They are not present in any of the .Net code base (unless you count the VB6 compatibility layer library) so should be considered deprecated and therefor ignored.

Off the top of my head I can't say as I've ever used them.



来源:https://stackoverflow.com/questions/927119/what-do-the-logical-functions-imp-and-eqv-do-in-vb6-has-anyone-found-a-real-wor

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!