News for hackers. Stuff that matters.
Re:Poll: How many programmers don't know about bit-wise oper... by anigbrowl on Sunday April 07, 2013 @06:06AM (#5506685)
I like the elegance of bitwise operations and use them sometimes in signal processing applications to avoid a performance hit, though I'm no expert. But I avoid them in any high level code because a) the compiler is likely going to optimize that anyway and b) to be as human-readable as possible, the code should clearly describe the objective rather than exploit the underlying mechanism. In other words if I want to multiply or divide then I prefer to write that than rely on the reader's knowledge of what bit-shifting does, and also so that the code in question would run properly on some hypothetical ternary computer or suchlike. As I'm mainly a hobby/ad-hoc programmer I can afford not to care about the probable overhead this imposes.

Great question, I hope this stimulates some discussion.

Re:Poll: How many programmers don't know about bit-wise oper... by justincormack on Sunday April 07, 2013 @06:52AM (#5506766)
Perfomance uses are pretty pointless now, as I discovered ten years ago when I found that gcc could turn masked shifts into a native rotate. So for multiply or divide just do so. Obviously where the underlying ops are xor etc, you use them. Most of the time I find myself using the for masking flags in system calls nowdays though and similar.
Re:Poll: How many programmers don't know about bit-wise oper... by saravk on Sunday April 07, 2013 @06:58AM (#5506777)
This is where macros (C) come in to play. Using macros (do all the bit shifting and masking inside) you can write very human readable code that is easy to maintain and while at the same time offers all the advantages of using bit-masks.

The major advantage of bitwise operators for me is the memory savings that come with them. I used to write the route calculation algorithms for routers and every bit/byte save had an tremendous impact on the total capacity of the router. We use bitfields to set and store various things from simple flags to multi-bit values, all inside a single integer variable.

Re:Poll: How many programmers don't know about bit-wise oper... by anigbrowl on Sunday April 07, 2013 @08:55PM (#5509438)
Great point and excellent context.
Re:Poll: How many programmers don't know about bit-wise oper... by thethomaseffect on Sunday April 07, 2013 @06:40AM (#5506751)
This post illustrates my sentiment too. It's great fun to try and be clever but unless they're necessary they're probably a bad idea.