3 ms·
Dividing by two is just a right shift.
by secondcoming 4y ago
Dividing by two is just a right shift.
- robocat 4y agoOnly if you are dealing with unsigned integers. For signed integers, you need to be careful depending on the language you are using. Most languages provide a signed right shift that doesn’t lose the sign. Personally, I think shift should always have been a bitwise operator, without sign extension. To me signed right shift feels as sensible as right shifting a floating point number - a shift is bitwise and not an arithmetical operator. But I guess that’s what comes from being brought up on healthy machine code by robots in the steel jungle. C recommendation: “INT13-C. Use bitwise operators only on unsigned operands” https://wiki.sei.cmu.edu/confluence/plugins/servlet/mobile?contentId=87152374 https://wiki.sei.cmu.edu/confluence/plugins/servlet/mobile?c...