Multiples of 4 ( An Interesting Method ) | An interesting XOR based method to check if a number is multiple of 4. ; Returns true if n is a multiple of 4. ; Driver code to print multiples of 4 ; Printing multiples of 4 using above method
#include <bits/stdc++.h> NEW_LINE using namespace std ; bool isMultipleOf4 ( long long n ) { if ( n == 0 ) return true ; return ( ( ( n >> 2 ) << 2 ) == n ) ; } int main ( ) { for ( int n = 0 ; n <= 42 ; n ++ ) if ( isMultipleOf4 ( n ) ) cout << n << " ▁ " ; return 0 ; }