<script> for (var i=0; i<16; i++) { var a = ("000"+i.toString(2)).substr(-4), b = [1,0,1,1].every(function(el,k) { return el == a[k] }) document.write(a+" => "+b+"<br>")} </script>