Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

133
Vistas
Bit shifting Left yields a negative number?

I'm trying to bitshift a number. Usually it works as expected, clipping anything above 32 bits.

num=2200131600391;
console.log((num).toString(2));   //100000000001000010000100000000000000000111
console.log((num>>1).toString(2));            //100001000010000000000000000011

However when I bitshift left once, the result becomes negative, and the numbers seem random.

console.log((num<<1).toString(2));          //-1111011110111111111111111110010

In order to verify whether the issue is with shifting left, I tried this.

console.log((num).toString(2));   //100000000001000010000100000000000000000111
console.log((num<<2).toString(2));              //1000010000000000000000011100
console.log((num<<3).toString(2));             //10000100000000000000000111000

So left shifting twice, thrice, and presumably any number more than once, doesn't give an error. Is there something unique about <<1 operator that is giving unexpected results?

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda