PRB: Result Incorrect with Bitwise AND Operator w/ Hex Values

    Article ID: Q116498
    Creation Date: 20-JUN-1994
    Revision Date: 19-SEP-1996

    The information in this article applies to:

    • Microsoft Access versions 1.0, 1.1, 2.0, 7.0

    SYMPTOMS

    Moderate: Requires basic macro, coding, and interoperability skills.

    When you use the bitwise AND operator against two hexadecimal numbers, you may receive incorrect results.

    CAUSE

    This behavior occurs when an integer is promoted and sign-extended to a long number. For example, if you enter the expression

       ?HEX(&HFFFFFFFF AND &H0000FFFF)
    
    
    in the Debug window (or the Immediate window in versions 1.x and 2.0), you would expect to receive the value H0000FFFF as the result. However, the number &H0000FFFF is promoted and sign-extended to a long integer, to return the value &HFFFFFFFF.

    RESOLUTION

    Add a trailing ampersand (&) to the hexadecimal numbers. This causes Microsoft Access to interpret the numbers as long integers, thus preventing the sign-extension from taking place. For example, the expression

       ?HEX(&HFFFFFFFF& AND &H0000FFFF&)
    
    
    results in the expected value &H0000FFFF.


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.
©1997 Microsoft Corporation. All rights reserved. Legal Notices.

Additional reference words: 1.00 1.10 2.00 7.00
KBCategory: kbprg
KBSubcategory: MdlOthr