Created
September 5, 2012 05:04
-
-
Save hisaos/3630838 to your computer and use it in GitHub Desktop.
deg2binTable
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function deg2binTable(num, pow) { | |
var result = []; | |
var maxNum = Math.pow(2, pow - 1); | |
for(var i = 0; i <= num; i++) | |
{ | |
var target = i; | |
var nesNum = maxNum; | |
var packing = ""; | |
var str = ""; | |
while(target < nesNum) { packing += "0"; nesNum >>= 1; } | |
while(target > 0) | |
{ | |
str += "" + (target & 1); | |
target >>= 1; | |
} | |
str += packing; | |
result.push(str.reverse(str)); | |
} | |
return result; | |
} | |
String.prototype.reverse = function(str) | |
{ | |
result = ""; | |
for(var i = str.length - 1; i >= 0; i--) | |
{ | |
result += str[i]; | |
} | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment