Bit And operation - C Operator

C examples for Operator:Bit Operator

Introduction

Suppose you declare the following variables:

Demo Code

#include <stdio.h> 

int main(void) { 
    /*  w ww . ja  v a2s . c  o  m*/
    int x = 13;
    int y = 6;
    int z = x & y;                     // AND corresponding bits of x and y
    
    printf("%d",z);
    return 0; 
} 

Result

After the third statement, z will have the value 4 (binary 100).

This is because the corresponding bits in x and y are combined as follows:

x           0      0     0      0     1     1      0     1
y           0      0     0      0     0     1      1     0
x & y       0      0     0      0     0     1      0     0

Related Tutorials