Hi guys! I have this simple code: //$UT = parseInt(document.getElementById("XML_type").value); //$ASZ = document.getElementById("XML_person").value; $UT = 1; $ASZ = "0123456789101"; $LE= $ASZ.length; if(($UT&2 == 2 && $LE != 13) || ($UT&2 != 2 && $LE> 0)){ msg = "ALERT"; console.log(msg); } Code (markup): I just simply cant understand what's going on... If $LE= 13 there is no way to go to the statement. I think i strongly misunderstand something Help plz!
What is the $UT&2 meant to be checking? Looks like string concatenation but then comparing to an integer I had a mess about changing the & to a + var UT = 1; var ASZ = "0123456789101"; //var ASZ = "012345678910"; var LE = ASZ.length; console.log(UT & 2); console.log(LE); if ((UT + 2 == 2 && LE != 13) || (UT + 2 != 2 && LE > 0)) { msg = "ALERT"; console.log(msg); } if (UT + 2 == 2 && LE != 13) { msg = "ALERT1"; console.log(msg); } else if(UT + 2 != 2 && LE > 0) { msg = "ALERT2"; console.log(msg); } Code (JavaScript):
Thanks for your reply! I got it! The correct way to put the & operator into '()', as both are logical expressions, and == has the priority over the &. Grrr //$UT = parseInt(document.getElementById("XML_type").value); //$ASZ = document.getElementById("XML_person").value; $UT = 1; $ASZ = "0123456789101"; $LE= $ASZ.length; if((($UT&2) == 2 && $LE != 13) || (($UT&2) != 2 && $LE> 0)){ msg = "ALERT"; console.log(msg); } Code (markup):
Since you're only evaluating binary and, you don't need to == 2 in the first bloody place. You're only checking one binary bit, so it's either going to be 0 or 2. With zero being boolean false, you could simply have written that as: if ( (($UT & 2) && $LE != 13) || (!($UT & 2) && $LE > 0) ) { Code (markup): Since we have loose boolean, use it. Same as doing a "test" in assembler, jz or jnz. Also if LE would never be negative, you could ditch the > 0 for just && $LE Though this isn't PHP, what's with all the dollar sign prefixing?