Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

151
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda