Skip to content

Instantly share code, notes, and snippets.

@akoluthic
Last active December 21, 2015 04:48
Show Gist options
  • Save akoluthic/6251723 to your computer and use it in GitHub Desktop.
Save akoluthic/6251723 to your computer and use it in GitHub Desktop.
Javascript - Determine power of 2 (log2)
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment