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

180
Visualizações
Check if flags are set in big integer

I have two flags "32" and "64" which need to be checked if they're included inside an integer variable.

Therefore I'm using the following code which is working fine with "small integers". For example if the integer variable is "33555378" it outputs the right results.

Now I have the problem that the integer variable is "12261800583900083122" and the script doesn't seem to work correctly.

How do I check if flags are set in big integers correctly?

This is the JSFiddle.

Code:

var flags = {
    Horde: 32, 
    Allianz: 64,
}

var flag = 12261800583900083122;

if ((flag & flags.Horde) == flags.Horde && (flag & flags.Allianz) == flags.Allianz) {
     console.log('Both');
} else if ((flag & flags.Allianz) == flags.Allianz) {
     console.log('Allianz');
} else if ((flag & flags.Horde) == flags.Horde) {
     console.log('Horde');
} else {
     console.log('Nothing');
}
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

I think using BigInt (adding n after numbers) for both flags and flag can fix your problem;

var flags = {
    Horde: 32n, 
    Allianz: 64n,
}

var flag = 12261800583900083122n;

if ((flag & flags.Horde) == flags.Horde && (flag & flags.Allianz) == flags.Allianz) {
     console.log('Both');
} else if ((flag & flags.Allianz) == flags.Allianz) {
     console.log('Allianz');
} else if ((flag & flags.Horde) == flags.Horde) {    
     console.log('Horde');
} else {
     console.log('Nothing');
}

This results as Horde.

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