function log2(val) { return Math.log(val) / Math.LN2; } //find the number of flags a musical note gets alert(log2(8) - 2); //8th notes get 1 flag alert(log2(128) - 2); //128th notes get 5 flags