How to calculate bit flag in javascript?

im writing a free tool for SEO ... the api implementation of seomoz and flags is as follows

URL Metric,Bit Flag
Title,1
URL,4
Subdomain,8
Root Domain,16
External Links,32
Links,2048
mozRank,16384
mozTrust,131072

These are just a few, but I don’t know how to calculate the correct bit flag in javascript ... is it just the OR of all the whole flags that I want to use? a small snippet to show me how to make a var that contains some of these flags would be awesome ...

thank you for your help!

+3
source share
2 answers

is it just the OR of all flag integers that I want to use?

Yes. Title|URL|Links(etc.) will be1|4|2048

+3
source

Like in C:

var flags = 0;
// *snip*
flags |= MyFlag;
flags |= MyOtherFlag;
// *snip*
if ((flags & MyFlag) == MyFlag)
{
    // do stuff
}
+5
source

Source: https://habr.com/ru/post/1730765/


All Articles