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

128
Vistas
Bitwise operations on large numbers

This works as expected:

> 0b1111
15
> 0b1111 & 0b1111
15

But this doesn't:

> 0b11111111111111111111111111111111
4294967295
> 0b11111111111111111111111111111111 & 0b11111111111111111111111111111111
-1

What's going on here? And how can I safely perform bitwise operations on large (up to 2^32) numbers in Javascript?

Update: This is below Number.MAX_SAFE_INTEGER so I don't believe there should be a loss of precision.

about 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

What's going on here?

JavaScript's bitwise operators will interpret the result as a signed 32-bit number (one exception is the >>> operator), but apart from that, the result is correct.

And how can I safely perform bitwise operations on large (up to 2^32) numbers in Javascript?

Apply >>> 0 to the result so the result is interpreted as an unsigned 32 bit number:

let res = (0b11111111111111111111111111111111 
            & 0b11111111111111111111111111111111) >>> 0;

console.log(res);

about 4 years ago · Santiago Trujillo Denunciar
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