Skip to content

Commit

Permalink
Feature Enhancement: Added Decimal Output, Division Method, OR,AND ,X…
Browse files Browse the repository at this point in the history
…OR Operators for Binary Inputs
  • Loading branch information
isid555 committed Aug 14, 2024
1 parent 2a1cfa1 commit 0c605a9
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
8 changes: 8 additions & 0 deletions Calculators/Binary-Calculator/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,22 @@ <h1>Binary Calculator</h1>
<option value="add">Addition</option>
<option value="subtract">Subtraction</option>
<option value="multiply">Multiplication</option>
<option value="division">Division</option>
<option value="leftShift">Left Shift</option>
<option value="rightShift">Right Shift</option>
<option value="and">AND Operator</option>
<option value="or">OR Operator</option>
<option value="xor">XOR Operator</option>
</select>
</div>
<button type="button" onclick="calculate()">Calculate</button>
</form>
<div id="results">
<p id="result"></p>
<p id="decimal"></p>
</div>
<div id="decimals">

</div>
</div>
<script src="script.js"></script>
Expand Down
24 changes: 23 additions & 1 deletion Calculators/Binary-Calculator/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,44 @@ function calculate() {
const num1 = parseInt(binary1, 2);
const num2 = parseInt(binary2, 2);
let result;

let decimal;
// Perform the selected operation
switch (operation) {
case "add":
result = (num1 + num2).toString(2);
decimal = (num1 + num2);
break;
case "subtract":
result = (num1 - num2).toString(2);
decimal = (num1 - num2);
break;
case "multiply":
result = (num1 * num2).toString(2);
decimal = (num1 * num2);
break;
case "leftShift":
result = (num1 << num2).toString(2);
decimal = (num1 << num2);
break;
case "rightShift":
result = (num1 >> num2).toString(2);
decimal = (num1 >> num2);
break;
case "division":
result = (num1 / num2).toString(2);
decimal = (num1 / num2);
break;
case "and":
result = (num1 && num2).toString(2);
decimal = (num1 && num2);
break;
case "or":
result = (num1 || num2).toString(2);
decimal = (num1 || num2);
break;
case "xor":
result = (num1 ^ num2).toString(2);
decimal = (num1 ^ num2);
break;
default:
alert("Invalid operation.");
Expand All @@ -39,4 +60,5 @@ function calculate() {

// Display the result
document.getElementById('result').innerText = `Result: ${result}`;
document.getElementById('decimal').innerText = `Decimal Value: ${decimal}`;
}
3 changes: 2 additions & 1 deletion Calculators/Binary-Calculator/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ body {
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
transition: transform 0.3s;
width: 500px;
height: 400px;
height: 450px;
}

.container:hover {
Expand Down Expand Up @@ -79,6 +79,7 @@ button:hover {
}

#results {

margin-top: 20px;
text-align: center;
}

1 comment on commit 0c605a9

@isid555
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Title: Feature Enhancement: Added Decimal Output, Division Method, OR, and XOR Operators for Binary Inputs

Description:

I have made the following improvements to the project, which enhances the functionality and addresses missing features:

Added Decimal Output:

A new parameter p has been introduced that allows the results to be displayed in decimal format in addition to binary. This enhances usability by providing users with a more familiar numerical representation.
Implemented Division Method:

Previously, the division operation was missing from the set of available operations. This method has now been implemented, enabling division of two binary inputs.
Added OR ,AND, XOR Operators:

The binary operations set has been expanded to include the OR ,AND, XOR operators, allowing for more complex logical operations between two binary inputs.

Impact:

These enhancements improve the versatility of the system by supporting additional operations and providing more output options. This will be especially beneficial for users who need both binary and decimal outputs and require the ability to perform OR and XOR operations on binary inputs.

Screenshots

image

image

Please sign in to comment.