13

I'm trying to apply this code: How to get X Y Z coordinates of tile by click on Leaflet map - which contains bitwise operator "<<". In the environment that I'm running it on (NodeJS, ExpressJS, AngularJS), codes are checked by ESLint upon compiling it but I need the solution given on the link. I get this error on compilation .

Unexpected use of '<<' no-bitwise

According to this link: http://eslint.org/docs/rules/no-bitwise - ESLint disallows bitwise operators. Is there any way to bypass this rule or if not, provide an alternate calculation that produces similar results to bitwise operation '<<'?

I hope my question is clear, thanks.

1
  • 2
    Each bit you shift left is the same as multiplying with its self. Power of two. So 2<<3 is the same as Math.pow(2,3). Will work for all numbers except 1, you will have to treat that as a special case. c = a << b can be done c = a===1?Math.pow(2,b-1):Math.pow(a,b);
    – Blindman67
    Aug 18, 2015 at 10:20

2 Answers 2

24

You need to add the comment //eslint-disable-line no-bitwise on the line you'd like for es-lint to ignore

e.g.

var x = 5 << 5; //eslint-disable-line no-bitwise
2
  • Thanks! Works like a charm. Aug 19, 2015 at 4:10
  • 1
    @YuriZarubin is there any other alternative to do the same thing without adding //eslint-disable-line no-bitwise in the source code. Thank You Apr 6, 2021 at 7:40
1

For power of two you can use Math.pow

const scale = Math.pow( 2, zoom );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.