Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

179
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!