Created
August 10, 2017 04:11
-
-
Save ChrisCates/8b6d412f3c23585f94c328ac4cb4b09f to your computer and use it in GitHub Desktop.
Bitwise in Node.js
This file contains hidden or 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
| module.exports = (value1, value2) => { | |
| let a = value1.toString().split(""); | |
| let b = value2.toString().split(""); | |
| let new_value = []; | |
| for (i = 0; i < a.length; i++) { | |
| let apos = a[i]; | |
| let bpos = b[i]; | |
| if (apos == "1") { | |
| if (apos == bpos) { | |
| new_value.push("1"); | |
| } else { | |
| new_value.push("0"); | |
| } | |
| } else { | |
| new_value.push("0"); | |
| } | |
| } | |
| return new_value.join(""); | |
| } |
This file contains hidden or 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
| module.exports = (value1, value2) => { | |
| var a = value1.toString().split(""); | |
| var b = parseInt(value2); | |
| var new_value = []; | |
| for (var i = 0; i < a.length; i++) { | |
| new_value.push("0"); | |
| } | |
| for (var i = 0; i < a.length; i++) { | |
| if (a[i - b]) { | |
| new_value[i - b] = a[i]; | |
| } | |
| } | |
| return new_value.join(""); | |
| } |
This file contains hidden or 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
| module.exports = (value1, value2) => { | |
| let a = value1.toString().split(""); | |
| let b = value2.toString().split(""); | |
| let new_value = []; | |
| for (i = 0; i < a.length; i++) { | |
| let apos = a[i]; | |
| let bpos = b[i]; | |
| if (apos == "1" || bpos == "1") { | |
| new_value.push("1"); | |
| } else { | |
| new_value.push("0"); | |
| } | |
| } | |
| return new_value.join(""); | |
| } |
This file contains hidden or 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
| module.exports = (value1, value2) => { | |
| var a = value1.toString().split(""); | |
| var b = parseInt(value2); | |
| var new_value = []; | |
| for (var i = 0; i < a.length; i++) { | |
| if (a[0] == "1" && i < b) { | |
| new_value.push("1"); | |
| } else { | |
| new_value.push("0"); | |
| } | |
| } | |
| for (var i = 0; i < a.length; i++) { | |
| if (a[i + b]) { | |
| new_value[i + b] = a[i]; | |
| } | |
| } | |
| return new_value.join(""); | |
| } |
This file contains hidden or 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
| module.exports = (value1, value2) => { | |
| var a = value1.toString().split(""); | |
| var b = parseInt(value2); | |
| var new_value = []; | |
| for (var i = 0; i < a.length; i++) { | |
| new_value.push("0"); | |
| } | |
| for (var i = 0; i < a.length; i++) { | |
| if (a[i + b]) { | |
| new_value[i + b] = a[i]; | |
| } | |
| } | |
| return new_value.join(""); | |
| } |
This file contains hidden or 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
| module.exports = (value1, value2) => { | |
| let a = value1.toString().split(""); | |
| let b = value2.toString().split(""); | |
| let new_value = []; | |
| for (i = 0; i < a.length; i++) { | |
| let apos = a[i]; | |
| let bpos = b[i]; | |
| if (apos == "1" && bpos == "0") { | |
| new_value.push("1"); | |
| } else if (apos == "0" && bpos == "1") { | |
| new_value.push("1"); | |
| } else { | |
| new_value.push("0"); | |
| } | |
| } | |
| return new_value.join(""); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment