Comments on Linux C Programming Tutorial Part 14 - Bitwise operators practical examples

In one of our earlier articles, we discussed the basics of bitwise operators. I hope you went through that article and are now ready to witness and understand some practical usage examples of these operators.

1 Comment(s)

Add comment

Please register in our forum first to comment.

Comments

By: dgrb

I'm not going to discuss your placement of braces ("curly bracket") as that is almost a matter of religous belief.

But you really need to do something about your indentation, which is, to say the least, inconsistent.

The worst example is probably this, from program #3:

if(((num>>position)&1) == 1) printf("\nBit at the position is 1"); else printf("\nBit at the position is 0"); You need to indent the same number of spaces each time (studies have shown that from 2 to 4 are the most effective offsets): here you use 1, in other places you use 2 sometimes 3.Also you should *always* use the brace for any control structure like if, when, for,even when there is only a single statement depending on it: it is all too easy to add another statement which you intend to be part of the if, while, etc but is not because you forgot to add the braces. Trust me, I've been coding in C for over 35 years...