Skip to content

Commit

Permalink
Merge pull request #111 from Satyasn01/feature/not-button
Browse files Browse the repository at this point in the history
NOT button [ all conflicts resolved ]
  • Loading branch information
Alitindrawan24 authored Oct 15, 2024
2 parents 669aaef + 7456f54 commit dca6f05
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
3 changes: 2 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,14 @@
</tr>

<tr>
<td><input class="button" type="button" value="NOT" onclick="bitwiseNOT()"></td>
<td><input class="button" type="button" value="AND" onclick="bitwiseAND()"></td>
<td><input class="button" type="button" value="OR" onclick="bitwiseOR()"></td>
<td><input class="button" type="button" value="XOR" onclick="bitwiseXOR()"></td>
<td><input class="button" type="button" value="Gray" onclick="binaryToGray()"></td>
</tr>

<tr>
<td><input class="button" type="button" value="Gray" onclick="binaryToGray()"></td>
<td><input class="button" type="button" value="Float" onclick="binaryToFloat()"></td>
<td><input class="button" type="button" value="Parity" onclick="calculateParityBit()"></td>
<td><input class="button" type="button" value="Square" onclick="squareRootBinary()"></td>
Expand Down
16 changes: 16 additions & 0 deletions js/binaryCalculator.js
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,22 @@ const rolButton = document.querySelector('input[value="ROL"]');
rorButton.addEventListener("click", () => circularShift('right'));
rolButton.addEventListener("click", () => circularShift('left'));

function bitwiseNOT() {
let binaryInput = res.value;
let binaryInt = parseInt(binaryInput, 2);
if (!isNaN(binaryInt)) {
let numBits = binaryInput.length;

let invertedBinaryInt = ~binaryInt;
let mask = Math.pow(2, numBits) - 1;
let finalBinary = invertedBinaryInt & mask;

res.value = finalBinary.toString(2).padStart(numBits, '0');
} else {
res.value = "Invalid Input";
}
}

function bitwiseAND() {
const input = document.form.textview.value.split(",");
if (input.length === 2) {
Expand Down

0 comments on commit dca6f05

Please sign in to comment.