Performance of bitwise operators in javascript Performance of bitwise operators in javascript javascript javascript

Performance of bitwise operators in javascript


This is quite an old question, but no one seemed to answer the updated version.

The performance hit that you get with JavaScript that doesn't exist in C/C++ is the cast from floating point representation (how JavaScript strores all of its numbers) to a 32 bit integer to perform the bit manipulation and back.


Nobody uses hex anymore?

function hextoRgb(c) {    c = '0x' + c.substring(1);    return [(c >> 16) & 255, (c >> 8) & 255, c & 255]; }var c1 = hextoRgb('#191970');alert('rgb(' + c1.join(',') + ')');


I use bitwise shift of zero in JS to perform quick integer truncation:

var i=3.141532;var iTrunc=i>>0; //3