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

141
Views
Bitwise operations on large numbers

This works as expected:

> 0b1111
15
> 0b1111 & 0b1111
15

But this doesn't:

> 0b11111111111111111111111111111111
4294967295
> 0b11111111111111111111111111111111 & 0b11111111111111111111111111111111
-1

What's going on here? And how can I safely perform bitwise operations on large (up to 2^32) numbers in Javascript?

Update: This is below Number.MAX_SAFE_INTEGER so I don't believe there should be a loss of precision.

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

What's going on here?

JavaScript's bitwise operators will interpret the result as a signed 32-bit number (one exception is the >>> operator), but apart from that, the result is correct.

And how can I safely perform bitwise operations on large (up to 2^32) numbers in Javascript?

Apply >>> 0 to the result so the result is interpreted as an unsigned 32 bit number:

let res = (0b11111111111111111111111111111111 
            & 0b11111111111111111111111111111111) >>> 0;

console.log(res);

about 4 years ago · Santiago Trujillo 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!