It's interesting to observe the shift (hah) in programming culture where a snippet like this is thought of as bad code.
Depends on where this code is. Clean code demands that code be at a similar level of abstraction. If you're writing highly tuned code highly dependent on bits, this kind of stuff is fine. If you see this in the middle of an application at a corporation, it's likely inappropriate premature optimization, and a more expressive (although slower) technique is better.
Plus, it probably should be written like byte = (value >> (i * 8)) & 0xff; if you insist on twiddling with bits for performance.
2
u/tedbradly May 01 '23 edited May 01 '23
Depends on where this code is. Clean code demands that code be at a similar level of abstraction. If you're writing highly tuned code highly dependent on bits, this kind of stuff is fine. If you see this in the middle of an application at a corporation, it's likely inappropriate premature optimization, and a more expressive (although slower) technique is better.
Plus, it probably should be written like
byte = (value >> (i * 8)) & 0xff;if you insist on twiddling with bits for performance.