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

148
Vistas
Equality negation to determine Least Significant Bit

Basically, I want to check if the last significant bit is a 0. I already had a condition to test if the bit is set or not (or at least, I believe so) :

cells[x + y * cols] & 1 === 1

At some point, I need the negation of this, so I thought :

cells[x + y * cols] & 1 === 0

But I didn't get the expected result. So I just :

(!cells[x + y * cols] & 1 === 1)

Which seems more appropriate according to the expected result. I don't get the expected result actualy, in both case. Maybe the problem comes from somewhere else or maybe I'm just misunderstanding the use of the bitwise operator.

So first of all, why these line are differents:

console.log(!(4 & 1 === 1)); // true
console.log(4 & 1 === 0); // 0

I mean, obviously the LSB of 4 is 0. I would say the first one is the one I need though...

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You need to wrap the 4 & 1 into parenthesis like so

console.log((4 & 1) === 0);

Because if you don't, it prioritizes 1 === 0 which is false and then 4 & false which is the same as 4 & 0.

about 4 years ago · Juan Pablo Isaza 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