Need help in decoding Bitmask flags in Javascript
beginner in using bitwise operators here. I understand the differences between them, however I'm not able to decode correctly the user language from them. basically the backend gives me a number which I need to use for decoding user language.
static const int TlvLanguageMask = 0x0700;
static const int TlvEnglish = 0x0000;
static const int TlvFrench = 0x0100;
static const int TlvSwedish = 0x0200;
static const int TlvCzech = 0x0300;
static const int TlvGerman = 0x0400;
static const int TlvSpanish = 0x0500;
static const int TlvItalian = 0x0600;
static const int TlvRomanian = 0x0700;
this is what the backend written in C++ uses for setting the languages. in my frontend written in Javascript I did the following thing:
function decodeLanguagevalue(Languagecode){
let language;
const languages={
languagemask:1792,//1110 0000 000
english:0,//0
french:128<<1,//256 -->1000 0000 0
swedish:128<<2,//512-->1000 0000 00
czech:512^256,//768 -->1100 0000 00 french+swedish?
German:128<<3,//1024-->1000 0000 000
Spanish:1024^256,//1280-->1010 0000 000 german+french?
Italian:1280^256,//1536--> 1100 0000 000 spanish+french?
Romanian:1536^256//1792--> 1110 0000 000 italian+french?
}
switch (Languagecode) {
case Languagecode & languages.english:
language="UK"
break;
case Languagecode & languages.french:
language="French"
break;
case Languagecode & languages.swedish:
language="Swedish"
break;
case Languagecode & languages.french & languages.swedish:
language="CZech"
break;
case Languagecode & languages.German:
language="German"
break;
case Languagecode & languages.German & languages.french:
language="Spanish"
break;
case Languagecode & languages.Spanish & languages.french:
language="Italian"
break;
case Languagecode & languages.Italian & languages.french:
language="Romanian"
break;
default:
language="Unknown"
break;
}
return language
}
however this function always returns me Unknown. This basically means that I messed up with bitwise operators on the frontend.Can someone enlight me on these and help me decoding them correctly? thank you
Comments
Post a Comment