Skip to content

Instantly share code, notes, and snippets.

@chensoren
Last active December 17, 2015 08:39
Show Gist options
  • Save chensoren/5581387 to your computer and use it in GitHub Desktop.
Save chensoren/5581387 to your computer and use it in GitHub Desktop.
二进制文本转换
//第0, 2, 5, 11位为1, 其它位为0
//二进制应该为 010000100101
var digitArray = ['0', '2', '5', '11'];
var binByte;
for(i=0; i<digitArray.length; i++) {
binByte = binByte | 1 << digitArray[i];
}
console.log(binByte.toString(2))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment