Last active
September 5, 2021 18:50
-
-
Save ujjawalsidhpura/d7ff2d0a773d9941e9c80c0dbe4102f6 to your computer and use it in GitHub Desktop.
bitwise.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
Have the function BitwiseTwo(strArr) take the array of strings stored in strArr, | |
which will only contain two strings of equal length that represent binary numbers, | |
and return a final binary string that performed the bitwise AND operation on both strings. | |
A bitwise AND operation places a 1 in the new string where there is a 1 in both locations in the binary strings, | |
otherwise it places a 0 in that spot. For example: if strArr is ["10111", "01101"] | |
then your program should return the string "00101" |
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
function BitwiseTwo(strArr) { | |
let x = strArr[0].split(''); | |
let y = strArr[1].split(''); | |
let z = []; | |
for (let i = 0; i < x.length; i++) { | |
if (x[i] === '1' && y[i] === '1') { | |
z[i] = '1'; | |
} else { | |
z[i] = '0'; | |
} | |
} | |
return z.join('') | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment