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

182
Vistas
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 Respuestas
Responde la pregunta

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 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