Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

XL2000: How to Use the Imp Operator for Binary Comparison


View products that this article applies to.

This article was previously published under Q213706

↑ Back to the top


Summary

The Microsoft Visual Basic for Applications Imp operator is used to perform a logical implication on two expressions. If you are using the Imp operator with two numeric expressions as arguments, Microsoft Excel performs a bit-wise comparison of identically positioned bits.

↑ Back to the top


More information

The syntax for the Imp operator is as follows
result = expression1 Imp expression2
where expression1 and expressions2 are any expressions and result is any numeric variable.

When you use the Imp operator to perform a bit-wise comparison of identically positioned bits in two numeric expressions, the result of the bit-wise comparison is determined using the rules in the following table.
   Bit in Expression1   Bit in Expression2   Bit in Result
   -------------------------------------------------------
           1                     1                 1
           1                     0                 0
           0                     1                 1
           0                     0                 1
				
Microsoft provides programming examples for illustration only, without warranty either expressed or implied, including, but not limited to, the implied warranties of merchantability and/or fitness for a particular purpose. This article assumes that you are familiar with the programming language being demonstrated and the tools used to create and debug procedures. Microsoft support professionals can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific needs.
If you have limited programming experience, you may want to contact a Microsoft Certified Partner or Microsoft Advisory Services. For more information, visit these Microsoft Web sites:

Microsoft Certified Partners - https://partner.microsoft.com/global/30000104

Microsoft Advisory Services - http://support.microsoft.com/gp/advisoryservice

For more information about the support options that are available and about how to contact Microsoft, visit the following Microsoft Web site:http://support.microsoft.com/default.aspx?scid=fh;EN-US;CNTACTMS For example, if you run the following macro, a message box displays the value of -11:
Sub Imp_Example()

Dim a As Integer
Dim b As Integer
Dim result As Integer

   a =10
   b = 4

   result = a Imp b

   MsgBox result

End Sub
				
The value -11 is returned because the macro follows the rules in the table and uses twos complement notation. Using twos complement notation, the leftmost bit represents the sign bit. If this bit is 1, the number is negative; if this bit is 0 (zero), the number is positive. To convert a negative number from binary back to decimal, complement all of the bits (1 becomes 0 and 0 becomes 1), convert that number to decimal, change the sign of the decimal number, and then subtract 1.

In the example, where the Imp operator is used with the two numeric values 10 and 4. In binary form (2 bytes), these two numbers appear as follows:
   10:   0000000000001010
    4:   0000000000000100
				
Using the bit-wise comparison rules from the table yields the result value in binary form:
   10:   0000000000001010

    4:   0000000000000100
   --------------------------

   result:   1111111111110101
				
To determine the decimal equivalent of the result, use the twos complement rules of conversion as follows:
                                  Result: 1111111111110101

                     Complement each bit: 0000000000001010

Decimal equivalent of this binary number: 10

                 Opposite of this number: -10
    Subtract 1 (decimal value of result): -11
				

↑ Back to the top


References

For more information about the Imp Operator, in the Visual Basic Editor, click Microsoft Visual Basic Help on the Help menu, type imp operator in the Office Assistant or the Answer Wizard, and then click Search to view the topic.

↑ Back to the top


Keywords: KB213706, kbprogramming, kbinfo, kbhowto

↑ Back to the top

Article Info
Article ID : 213706
Revision : 8
Created on : 11/23/2006
Published on : 11/23/2006
Exists online : False
Views : 276