Well, one-by-one we’ve discussed each of the Bitwise Operator . Starting from Operation on Bits and Bitwise Operators , we moved on to Right/Left Bit Shift Operators then discussed Decimal Number to Binary Conversion Program . and at last One's Complement and XOR Operators . After having so much theoretical it’s time now for a nice Example Program, which is the topic of today’s post. The code here is basically to show how these bitwise operator are used rather than what they are used for. // Example Program to demonstrate how // One's Complement (~) and XOR (^) // Opeartors are used. #include<stdio.h> // prototype void showbits( short int ); // defined void showbits( short int dec_num) { short int loop, bit, and_mask; for (loop= 15 ; loop>= 0 ; loop--) { and_mask= 1 <<loop; bit=dec_num&and_mask; if (bit== 0 ) printf( "0" ); else printf( "1" );
A resource for learning PHP, HTML, CSS, JavaScript, C++, etc.