Skip to content

Latest commit

 

History

History
79 lines (68 loc) · 2.51 KB

File metadata and controls

79 lines (68 loc) · 2.51 KB
title Bitwise AND Operator: & | Microsoft Docs
ms.custom
ms.date 11/04/2016
ms.reviewer
ms.suite
ms.technology
cpp-language
ms.tgt_pltfrm
ms.topic language-reference
f1_keywords
bitand
dev_langs
C++
helpviewer_keywords
AND operator
bitwise operators, AND operator
& operator, bitwise operators
ms.assetid 76f40de3-c417-47b9-8a77-532f3fc990a5
caps.latest.revision 7
author mikeblome
ms.author mblome
manager ghogen
translation.priority.ht
cs-cz
de-de
es-es
fr-fr
it-it
ja-jp
ko-kr
pl-pl
pt-br
ru-ru
tr-tr
zh-cn
zh-tw

Bitwise AND Operator: &

Syntax

  
expression   
&  
 expression  
  

Remarks

The expressions may be other and-expressions, or (subject to the type restrictions mentioned below) equality expressions, relational expressions, additive expressions, multiplicative expressions, pointer to member expressions, cast expressions, unary expressions, postfix expressions, or primary expressions.

The bitwise AND operator (&) compares each bit of the first operand to the corresponding bit of the second operand. If both bits are 1, the corresponding result bit is set to 1. Otherwise, the corresponding result bit is set to 0.

Both operands to the bitwise AND operator must be of integral types. The usual arithmetic conversions covered in Standard Conversions, are applied to the operands.

Operator Keyword for &

The bitand operator is the text equivalent of &. There are two ways to access the bitand operator in your programs: include the header file iso646.h, or compile with the /Za (Disable language extensions) compiler option.

Example

// expre_Bitwise_AND_Operator.cpp  
// compile with: /EHsc  
// Demonstrate bitwise AND  
#include <iostream>  
using namespace std;  
int main() {  
   unsigned short a = 0xFFFF;      // pattern 1111 ...  
   unsigned short b = 0xAAAA;      // pattern 1010 ...  
  
   cout  << hex << ( a & b ) << endl;   // prints "aaaa", pattern 1010 ...  
}  

See Also

C++ Built-in Operators, Precedence and Associativity
C++ Built-in Operators, Precedence and Associativity
C Bitwise Operators