Code Smell 180 - BitWise Optimizations

Photo by Frédéric Barriol on Unsplash

Code Smell 180 - BitWise Optimizations

Bitwise operators are faster. Avoid these micro-optimizations

Maxi Contieri
·Nov 19, 2022·

2 min read

Subscribe to my newsletter and never miss my upcoming articles

Play this article

Table of contents

  • Problems
  • Solutions
  • Context
  • Sample Code
  • Detection
  • Exceptions
  • Tags
  • Conclusion
  • Relations
  • More Info
  • Disclaimer
  • Credits

TL;DR: Don't use bitwise operators unless your business model is bitwise logic.


  • Readability

  • Clevereness

  • Premature Optimization

  • Maintainability

  • Bijection Violation


  1. Improve readability


Some clever programmers solve problems we don't have.

We should optimize code based on evidence and use the scientific method.

We should benchmark only if necessary and improve code only if really necessary and bear the cost of changeability and maintainability.

Sample Code


const nowInSeconds = ~~( / 1000)


const nowInSeconds = Math.floor( / 1000)


[X] Semi-Automatic

We can tell our linters to warn us and manually check if it is worth the change.


  • Real-time and mission-critical software.


  • Premature Optimization


If we find this code in a pull request or code review, we need to understand the reasons. If they are not justified, we should do a rollback and change it to a normal logic.


More Info

Tilde Operator ~~

Javascript BitWise Operators


Code Smells are just my opinion.


Photo by Frédéric Barriol on Unsplash

Original Article Here.

Watch the little things; a small leak will sink a great ship.

Benjamin Franklin

This article is part of the CodeSmell Series.

Share this