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

129
Views
Bit shifting Left yields a negative number?

I'm trying to bitshift a number. Usually it works as expected, clipping anything above 32 bits.

num=2200131600391;
console.log((num).toString(2));   //100000000001000010000100000000000000000111
console.log((num>>1).toString(2));            //100001000010000000000000000011

However when I bitshift left once, the result becomes negative, and the numbers seem random.

console.log((num<<1).toString(2));          //-1111011110111111111111111110010

In order to verify whether the issue is with shifting left, I tried this.

console.log((num).toString(2));   //100000000001000010000100000000000000000111
console.log((num<<2).toString(2));              //1000010000000000000000011100
console.log((num<<3).toString(2));             //10000100000000000000000111000

So left shifting twice, thrice, and presumably any number more than once, doesn't give an error. Is there something unique about <<1 operator that is giving unexpected results?

about 4 years ago · Juan Pablo Isaza
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!