Binary Magic is a high-performance project designed for handling binary arithmetic operations, showcasing the versatility of multiple programming languages. This project demonstrates binary addition, subtraction, and multiplication using Python, JavaScript, TypeScript, C#, C++, and C.
- Binary Addition: Add two binary numbers efficiently.
- Binary Subtraction: Subtract one binary number from another seamlessly.
- Binary Multiplication: Multiply two binary numbers with precision.
- Python
- JavaScript
- TypeScript
- C#
- C++
- C
Make sure you have the following installed for TypeScript implementation:
- Node.js (LTS recommended)
- TypeScript
For other languages, ensure you have their respective compilers/interpreters set up.
-
Clone the repository:
git clone https://github.com/RlxChap2/Binary-Magic.git cd Binary-Magic
-
Install dependencies:
npm install
-
Compile TypeScript to JavaScript:
npm run build
-
Run the program:
npm start
This function performs binary addition by:
- Converting the binary strings (
bin1
andbin2
) to decimal usingparseInt
. - Adding the two decimal numbers.
- Converting the result back to a binary string using
toString(2)
.
This function performs binary subtraction by:
- Converting the binary strings (
bin1
andbin2
) to decimal usingparseInt
. - Subtracting the second decimal number from the first.
- Converting the result back to a binary string using
toString(2)
.
This function performs binary multiplication by:
- Converting the binary strings (
bin1
andbin2
) to decimal usingparseInt
. - Multiplying the two decimal numbers.
- Converting the result back to a binary string using
toString(2)
.
The example below demonstrates how to use the TypeScript functions:
const bin1 = "1010"; // Binary representation of 10 in decimal
const bin2 = "110"; // Binary representation of 6 in decimal
console.log("Addition: " + binaryAddition(bin1, bin2));
// Expected Output: "Addition: 10000" (10 + 6 = 16 in decimal, 10000 in binary)
console.log("Subtraction: " + binarySubtraction(bin1, bin2));
// Expected Output: "Subtraction: 100" (10 - 6 = 4 in decimal, 100 in binary)
console.log("Multiplication: " + binaryMultiplication(bin1, bin2));
// Expected Output: "Multiplication: 111100" (10 * 6 = 60 in decimal, 111100 in binary)
Equivalent implementations are available in Python, C#, C++, and C, ensuring consistency across platforms and programming environments.
This project is licensed under the MIT LICENCE.