Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function dec2bin(dec){
- return (dec >>> 0).toString(2); // >>> zero fill right shift due to signed bit
- }
- function bin2exclamation(bin){
- var arr = [];
- for(var i=0; i< bin.length; i++){
- arr.push(parseInt(bin.substr(i, 1)) === 1 ? 0 : 1);
- }
- return arr.join('');
- }
- function bin2int(bin){
- return parseInt(bin, 2);
- }
- var init = 100;
- init = dec2bin(init);
- console.log(init);
- init = bin2exclamation(init);
- console.log(init);
- init = bin2int(init);
- console.log(init);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement