This commit is contained in:
RafayAhmad7548 2024-06-16 18:53:25 +05:00
parent 37776af5db
commit ab03d5f10c
4045 changed files with 286212 additions and 3 deletions

View file

@ -0,0 +1,137 @@
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
class Binary {
private:
string binaryString;
int base;
int decimalNo;
public:
// Constructor (If base is greater than 2 first convert into base 10 using that base and then convert back into binary and change the base to 2)
Binary(string binaryStr, int base = 2){
toDecimal();
}
void toBinary(){
binaryString = "";
int temp = decimalNo;
while(temp > 0){
binaryString = char(temp%2 + '0') + binaryString;
temp /= 2;
}
}
void toDecimal(){
decimalNo = 0;
for(int i=0;i<binaryString.length();i++) decimalNo += (binaryString[i] - '0')*pow(2, binaryString.length()-1-i);
}
// Overloading + operator for addition
Binary operator+(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo + other.decimalNo;
result.toBinary();
return result;
}
// Overloading - operator for subtraction
Binary operator-(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo - other.decimalNo;
result.toBinary();
return result;
}
// Overloading += operator for addition
Binary& operator+=(const Binary& other){
this->decimalNo += other.decimalNo;
this->toBinary();
return *this;
}
// Overloading -= operator for subtraction
Binary& operator-=(const Binary& other){
this->decimalNo -= other.decimalNo;
this->toBinary();
return *this;
}
// Overloading * operator for multiplication (Convert to base 10 multiply and convert back into base 2)
Binary operator*(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo * other.decimalNo;
result.toBinary();
return result;
}
// Overloading / operator for division (Convert to base 10 divide and convert back into base 2)
Binary operator/(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo / other.decimalNo;
result.toBinary();
return result;
}
// Overloading % operator for modulus (Convert to base 10 modulus and convert back into base 2)
Binary operator%(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo % other.decimalNo;
result.toBinary();
return result;
}
// Overloading | operator for or
Binary operator|(const Binary& other) const{
Binary("", 2);
if(this->binaryString.length() < other.binaryString.length()){
for(int i=0;i<other.binaryString.length() - this->binaryString.length();i++){
this->binaryString = "0" + this->binaryString;
}
}
}
// Overloading ^ operator for xor
Binary operator^(const Binary& other) const{
}
// Overloading & operator for and
Binary operator&(const Binary& other) const{
}
// Overloading ! operator for 2's Compliment
Binary operator!() const{
}
// Overloading ~ operator for 1's Compliment
Binary operator~() const{
}
// Overloading left shift operator
Binary operator<<(int shiftAmount) const{
}
// Overloading right shift operator
Binary operator>>(int shiftAmount) const{
}
// Overloading input operator
friend istream& operator>>(istream& input, Binary& other){
}
// Overloading output operator (Display Both Binary as well as Integer value)
friend ostream& operator<<(ostream& output, const Binary& other){
}
};

View file

@ -0,0 +1,142 @@
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
class Binary {
private:
string binaryString;
int base;
int decimalNo;
public:
// Constructor (If base is greater than 2 first convert into base 10 using that base and then convert back into binary and change the base to 2)
Binary(string binaryStr, int base = 2){
toDecimal();
}
void toBinary(){
binaryString = "";
int temp = decimalNo;
while(temp > 0){
binaryString = char(temp%2 + '0') + binaryString;
temp /= 2;
}
}
void toDecimal(){
decimalNo = 0;
for(int i=0;i<binaryString.length();i++) decimalNo += (binaryString[i] - '0')*pow(2, binaryString.length()-1-i);
}
// Overloading + operator for addition
Binary operator+(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo + other.decimalNo;
result.toBinary();
return result;
}
// Overloading - operator for subtraction
Binary operator-(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo - other.decimalNo;
result.toBinary();
return result;
}
// Overloading += operator for addition
Binary& operator+=(const Binary& other){
this->decimalNo += other.decimalNo;
this->toBinary();
return *this;
}
// Overloading -= operator for subtraction
Binary& operator-=(const Binary& other){
this->decimalNo -= other.decimalNo;
this->toBinary();
return *this;
}
// Overloading * operator for multiplication (Convert to base 10 multiply and convert back into base 2)
Binary operator*(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo * other.decimalNo;
result.toBinary();
return result;
}
// Overloading / operator for division (Convert to base 10 divide and convert back into base 2)
Binary operator/(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo / other.decimalNo;
result.toBinary();
return result;
}
// Overloading % operator for modulus (Convert to base 10 modulus and convert back into base 2)
Binary operator%(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo % other.decimalNo;
result.toBinary();
return result;
}
// Overloading | operator for or
Binary operator|(const Binary& other){
Binary("", 2);
if(this->binaryString.length() < other.binaryString.length()){
for(int i=0;i<other.binaryString.length() - this->binaryString.length();i++){
this->binaryString = '0' + this->binaryString;
}
}
else if(this->binaryString.length() > other.binaryString.length()){
for(int i=0;i<this->binaryString.length() - other.binaryString.length();i++){
this->binaryString = '0' + this->binaryString;
}
}
}
// Overloading ^ operator for xor
Binary operator^(const Binary& other) const{
}
// Overloading & operator for and
Binary operator&(const Binary& other) const{
}
// Overloading ! operator for 2's Compliment
Binary operator!() const{
}
// Overloading ~ operator for 1's Compliment
Binary operator~() const{
}
// Overloading left shift operator
Binary operator<<(int shiftAmount) const{
}
// Overloading right shift operator
Binary operator>>(int shiftAmount) const{
}
// Overloading input operator
friend istream& operator>>(istream& input, Binary& other){
}
// Overloading output operator (Display Both Binary as well as Integer value)
friend ostream& operator<<(ostream& output, const Binary& other){
}
};

View file

@ -0,0 +1,142 @@
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
class Binary {
private:
string binaryString;
int base;
int decimalNo;
public:
// Constructor (If base is greater than 2 first convert into base 10 using that base and then convert back into binary and change the base to 2)
Binary(string binaryStr, int base = 2){
toDecimal();
}
void toBinary(){
binaryString = "";
int temp = decimalNo;
while(temp > 0){
binaryString = char(temp%2 + '0') + binaryString;
temp /= 2;
}
}
void toDecimal(){
decimalNo = 0;
for(int i=0;i<binaryString.length();i++) decimalNo += (binaryString[i] - '0')*pow(2, binaryString.length()-1-i);
}
// Overloading + operator for addition
Binary operator+(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo + other.decimalNo;
result.toBinary();
return result;
}
// Overloading - operator for subtraction
Binary operator-(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo - other.decimalNo;
result.toBinary();
return result;
}
// Overloading += operator for addition
Binary& operator+=(const Binary& other){
this->decimalNo += other.decimalNo;
this->toBinary();
return *this;
}
// Overloading -= operator for subtraction
Binary& operator-=(const Binary& other){
this->decimalNo -= other.decimalNo;
this->toBinary();
return *this;
}
// Overloading * operator for multiplication (Convert to base 10 multiply and convert back into base 2)
Binary operator*(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo * other.decimalNo;
result.toBinary();
return result;
}
// Overloading / operator for division (Convert to base 10 divide and convert back into base 2)
Binary operator/(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo / other.decimalNo;
result.toBinary();
return result;
}
// Overloading % operator for modulus (Convert to base 10 modulus and convert back into base 2)
Binary operator%(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo % other.decimalNo;
result.toBinary();
return result;
}
// Overloading | operator for or
Binary operator|(Binary& other){
Binary result("", 2);
if(this->binaryString.length() < other.binaryString.length()){
for(int i=0;i<other.binaryString.length() - this->binaryString.length();i++) this->binaryString = '0' + this->binaryString;
}
else if(this->binaryString.length() > other.binaryString.length()){
for(int i=0;i<this->binaryString.length() - other.binaryString.length();i++) other.binaryString = '0' + other.binaryString;
}
for(int i=0;i<this->binaryString.length();i++){
result.binaryString += this->binaryString[i] || other.binaryString[i];
}
}
// Overloading ^ operator for xor
Binary operator^(const Binary& other) const{
}
// Overloading & operator for and
Binary operator&(const Binary& other) const{
}
// Overloading ! operator for 2's Compliment
Binary operator!() const{
}
// Overloading ~ operator for 1's Compliment
Binary operator~() const{
}
// Overloading left shift operator
Binary operator<<(int shiftAmount) const{
}
// Overloading right shift operator
Binary operator>>(int shiftAmount) const{
}
// Overloading input operator
friend istream& operator>>(istream& input, Binary& other){
}
// Overloading output operator (Display Both Binary as well as Integer value)
friend ostream& operator<<(ostream& output, const Binary& other){
}
};

View file

@ -0,0 +1,119 @@
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
class Binary {
private:
string binaryString;
int base;
int decimalNo;
public:
// Constructor (If base is greater than 2 first convert into base 10 using that base and then convert back into binary and change the base to 2)
Binary(string binaryStr, int base = 2){
toDecimal();
}
void toBinary(){
binaryString = "";
int temp = decimalNo;
while(temp > 0){
binaryString = char(temp%2 + '0') + binaryString;
temp /= 2;
}
}
void toDecimal(){
decimalNo = 0;
for(int i=0;i<binaryString.length();i++) decimalNo += (binaryString[i] - '0')*pow(2, binaryString.length()-1-i);
}
// Overloading + operator for addition
Binary operator+(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo + other.decimalNo;
result.toBinary();
return result;
}
// Overloading - operator for subtraction
Binary operator-(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo - other.decimalNo;
result.toBinary();
return result;
}
// Overloading += operator for addition
Binary& operator+=(const Binary& other) const{
}
// Overloading -= operator for subtraction
Binary& operator-=(const Binary& other) const{
}
// Overloading * operator for multiplication (Convert to base 10 multiply and convert back into base 2)
Binary operator*(const Binary& other) const{
}
// Overloading / operator for division (Convert to base 10 divide and convert back into base 2)
Binary operator/(const Binary& other) const{
}
// Overloading % operator for modulus (Convert to base 10 modulus and convert back into base 2)
Binary operator%(const Binary& other) const{
}
// Overloading | operator for or
Binary operator|(const Binary& other) const{
}
// Overloading ^ operator for xor
Binary operator^(const Binary& other) const{
}
// Overloading & operator for and
Binary operator&(const Binary& other) const{
}
// Overloading ! operator for 2's Compliment
Binary operator!() const{
}
// Overloading ~ operator for 1's Compliment
Binary operator~() const{
}
// Overloading left shift operator
Binary operator<<(int shiftAmount) const{
}
// Overloading right shift operator
Binary operator>>(int shiftAmount) const{
}
// Overloading input operator
friend istream& operator>>(istream& input, Binary& other){
}
// Overloading output operator (Display Both Binary as well as Integer value)
friend ostream& operator<<(ostream& output, const Binary& other){
}
};

View file

@ -0,0 +1,135 @@
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
class Binary {
private:
string binaryString;
int base;
int decimalNo;
public:
// Constructor (If base is greater than 2 first convert into base 10 using that base and then convert back into binary and change the base to 2)
Binary(string binaryStr, int base = 2){
toDecimal();
}
void toBinary(){
binaryString = "";
int temp = decimalNo;
while(temp > 0){
binaryString = char(temp%2 + '0') + binaryString;
temp /= 2;
}
}
void toDecimal(){
decimalNo = 0;
for(int i=0;i<binaryString.length();i++) decimalNo += (binaryString[i] - '0')*pow(2, binaryString.length()-1-i);
}
// Overloading + operator for addition
Binary operator+(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo + other.decimalNo;
result.toBinary();
return result;
}
// Overloading - operator for subtraction
Binary operator-(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo - other.decimalNo;
result.toBinary();
return result;
}
// Overloading += operator for addition
Binary& operator+=(const Binary& other){
this->decimalNo += other.decimalNo;
this->toBinary();
return *this;
}
// Overloading -= operator for subtraction
Binary& operator-=(const Binary& other){
this->decimalNo -= other.decimalNo;
this->toBinary();
return *this;
}
// Overloading * operator for multiplication (Convert to base 10 multiply and convert back into base 2)
Binary operator*(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo * other.decimalNo;
result.toBinary();
return result;
}
// Overloading / operator for division (Convert to base 10 divide and convert back into base 2)
Binary operator/(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo / other.decimalNo;
result.toBinary();
return result;
}
// Overloading % operator for modulus (Convert to base 10 modulus and convert back into base 2)
Binary operator%(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo % other.decimalNo;
result.toBinary();
return result;
}
// Overloading | operator for or
Binary operator|(const Binary& other) const{
Binary("", 2);
if(this->binaryString.length() != other.binaryString.length()){
}
}
// Overloading ^ operator for xor
Binary operator^(const Binary& other) const{
}
// Overloading & operator for and
Binary operator&(const Binary& other) const{
}
// Overloading ! operator for 2's Compliment
Binary operator!() const{
}
// Overloading ~ operator for 1's Compliment
Binary operator~() const{
}
// Overloading left shift operator
Binary operator<<(int shiftAmount) const{
}
// Overloading right shift operator
Binary operator>>(int shiftAmount) const{
}
// Overloading input operator
friend istream& operator>>(istream& input, Binary& other){
}
// Overloading output operator (Display Both Binary as well as Integer value)
friend ostream& operator<<(ostream& output, const Binary& other){
}
};

View file

@ -0,0 +1,155 @@
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
class Binary {
private:
string binaryString;
int base;
int decimalNo;
public:
// Constructor (If base is greater than 2 first convert into base 10 using that base and then convert back into binary and change the base to 2)
Binary(string binaryStr, int base = 2){
toDecimal();
}
void toBinary(){
binaryString = "";
int temp = decimalNo;
while(temp > 0){
binaryString = char(temp%2 + '0') + binaryString;
temp /= 2;
}
}
void toDecimal(){
decimalNo = 0;
for(int i=0;i<binaryString.length();i++) decimalNo += (binaryString[i] - '0')*pow(2, binaryString.length()-1-i);
}
// Overloading + operator for addition
Binary operator+(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo + other.decimalNo;
result.toBinary();
return result;
}
// Overloading - operator for subtraction
Binary operator-(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo - other.decimalNo;
result.toBinary();
return result;
}
// Overloading += operator for addition
Binary& operator+=(const Binary& other){
this->decimalNo += other.decimalNo;
this->toBinary();
return *this;
}
// Overloading -= operator for subtraction
Binary& operator-=(const Binary& other){
this->decimalNo -= other.decimalNo;
this->toBinary();
return *this;
}
// Overloading * operator for multiplication (Convert to base 10 multiply and convert back into base 2)
Binary operator*(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo * other.decimalNo;
result.toBinary();
return result;
}
// Overloading / operator for division (Convert to base 10 divide and convert back into base 2)
Binary operator/(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo / other.decimalNo;
result.toBinary();
return result;
}
// Overloading % operator for modulus (Convert to base 10 modulus and convert back into base 2)
Binary operator%(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo % other.decimalNo;
result.toBinary();
return result;
}
// Overloading | operator for or
Binary operator|(const Binary& other) const{
Binary result("", 2);
// if(this->binaryString.length() < other.binaryString.length()){
// for(int i=0;i<other.binaryString.length() - this->binaryString.length();i++) this->binaryString = '0' + this->binaryString;
// }
// else if(this->binaryString.length() > other.binaryString.length()){
// for(int i=0;i<this->binaryString.length() - other.binaryString.length();i++) other.binaryString = '0' + other.binaryString;
// }
// for(int i=0;i<this->binaryString.length();i++){
// result.binaryString += this->binaryString[i] || other.binaryString[i];
// }
result.decimalNo = this->decimalNo | other.decimalNo;
result.toBinary();
return result;
}
// Overloading ^ operator for xor
Binary operator^(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo ^ other.decimalNo;
result.toBinary();
return result;
}
// Overloading & operator for and
Binary operator&(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo & other.decimalNo;
result.toBinary();
return result;
}
// Overloading ! operator for 2's Compliment
Binary operator!() const{
}
// Overloading ~ operator for 1's Compliment
Binary operator~() const{
}
// Overloading left shift operator
Binary operator<<(int shiftAmount) const{
Binary result("", 2);
result.decimalNo = this->decimalNo << shiftAmount;
result.toBinary();
return result;
}
// Overloading right shift operator
Binary operator>>(int shiftAmount) const{
}
// Overloading input operator
friend istream& operator>>(istream& input, Binary& other){
}
// Overloading output operator (Display Both Binary as well as Integer value)
friend ostream& operator<<(ostream& output, const Binary& other){
}
};

View file

@ -0,0 +1,158 @@
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
class Binary {
private:
string binaryString;
int base;
int decimalNo;
public:
// Constructor (If base is greater than 2 first convert into base 10 using that base and then convert back into binary and change the base to 2)
Binary(string binaryStr, int base = 2){
toDecimal();
}
void toBinary(){
binaryString = "";
int temp = decimalNo;
while(temp > 0){
binaryString = char(temp%2 + '0') + binaryString;
temp /= 2;
}
}
void toDecimal(){
decimalNo = 0;
for(int i=0;i<binaryString.length();i++) decimalNo += (binaryString[i] - '0')*pow(2, binaryString.length()-1-i);
}
// Overloading + operator for addition
Binary operator+(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo + other.decimalNo;
result.toBinary();
return result;
}
// Overloading - operator for subtraction
Binary operator-(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo - other.decimalNo;
result.toBinary();
return result;
}
// Overloading += operator for addition
Binary& operator+=(const Binary& other){
this->decimalNo += other.decimalNo;
this->toBinary();
return *this;
}
// Overloading -= operator for subtraction
Binary& operator-=(const Binary& other){
this->decimalNo -= other.decimalNo;
this->toBinary();
return *this;
}
// Overloading * operator for multiplication (Convert to base 10 multiply and convert back into base 2)
Binary operator*(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo * other.decimalNo;
result.toBinary();
return result;
}
// Overloading / operator for division (Convert to base 10 divide and convert back into base 2)
Binary operator/(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo / other.decimalNo;
result.toBinary();
return result;
}
// Overloading % operator for modulus (Convert to base 10 modulus and convert back into base 2)
Binary operator%(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo % other.decimalNo;
result.toBinary();
return result;
}
// Overloading | operator for or
Binary operator|(const Binary& other) const{
Binary result("", 2);
// if(this->binaryString.length() < other.binaryString.length()){
// for(int i=0;i<other.binaryString.length() - this->binaryString.length();i++) this->binaryString = '0' + this->binaryString;
// }
// else if(this->binaryString.length() > other.binaryString.length()){
// for(int i=0;i<this->binaryString.length() - other.binaryString.length();i++) other.binaryString = '0' + other.binaryString;
// }
// for(int i=0;i<this->binaryString.length();i++){
// result.binaryString += this->binaryString[i] || other.binaryString[i];
// }
result.decimalNo = this->decimalNo | other.decimalNo;
result.toBinary();
return result;
}
// Overloading ^ operator for xor
Binary operator^(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo ^ other.decimalNo;
result.toBinary();
return result;
}
// Overloading & operator for and
Binary operator&(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo & other.decimalNo;
result.toBinary();
return result;
}
// Overloading ! operator for 2's Compliment
Binary operator!() const{
}
// Overloading ~ operator for 1's Compliment
Binary operator~() const{
}
// Overloading left shift operator
Binary operator<<(int shiftAmount) const{
Binary result("", 2);
result.decimalNo = this->decimalNo << shiftAmount;
result.toBinary();
return result;
}
// Overloading right shift operator
Binary operator>>(int shiftAmount) const{
Binary result("", 2);
result.decimalNo = this->decimalNo >> shiftAmount;
result.toBinary();
return result;
}
// Overloading input operator
friend istream& operator>>(istream& input, Binary& other){
}
// Overloading output operator (Display Both Binary as well as Integer value)
friend ostream& operator<<(ostream& output, const Binary& other){
}
};

View file

@ -0,0 +1,121 @@
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
class Binary {
private:
string binaryString;
int base;
int decimalNo;
public:
// Constructor (If base is greater than 2 first convert into base 10 using that base and then convert back into binary and change the base to 2)
Binary(string binaryStr, int base = 2){
toDecimal();
}
void toBinary(){
binaryString = "";
int temp = decimalNo;
while(temp > 0){
binaryString = char(temp%2 + '0') + binaryString;
temp /= 2;
}
}
void toDecimal(){
decimalNo = 0;
for(int i=0;i<binaryString.length();i++) decimalNo += (binaryString[i] - '0')*pow(2, binaryString.length()-1-i);
}
// Overloading + operator for addition
Binary operator+(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo + other.decimalNo;
result.toBinary();
return result;
}
// Overloading - operator for subtraction
Binary operator-(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo - other.decimalNo;
result.toBinary();
return result;
}
// Overloading += operator for addition
Binary& operator+=(const Binary& other){
this->decimalNo += other.decimalNo;
this->toBinary();
return *this;
}
// Overloading -= operator for subtraction
Binary& operator-=(const Binary& other) const{
}
// Overloading * operator for multiplication (Convert to base 10 multiply and convert back into base 2)
Binary operator*(const Binary& other) const{
}
// Overloading / operator for division (Convert to base 10 divide and convert back into base 2)
Binary operator/(const Binary& other) const{
}
// Overloading % operator for modulus (Convert to base 10 modulus and convert back into base 2)
Binary operator%(const Binary& other) const{
}
// Overloading | operator for or
Binary operator|(const Binary& other) const{
}
// Overloading ^ operator for xor
Binary operator^(const Binary& other) const{
}
// Overloading & operator for and
Binary operator&(const Binary& other) const{
}
// Overloading ! operator for 2's Compliment
Binary operator!() const{
}
// Overloading ~ operator for 1's Compliment
Binary operator~() const{
}
// Overloading left shift operator
Binary operator<<(int shiftAmount) const{
}
// Overloading right shift operator
Binary operator>>(int shiftAmount) const{
}
// Overloading input operator
friend istream& operator>>(istream& input, Binary& other){
}
// Overloading output operator (Display Both Binary as well as Integer value)
friend ostream& operator<<(ostream& output, const Binary& other){
}
};

View file

@ -0,0 +1,172 @@
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
class Binary {
private:
string binaryString;
int base;
int decimalNo;
public:
// Constructor (If base is greater than 2 first convert into base 10 using that base and then convert back into binary and change the base to 2)
Binary(string binaryStr, int base = 2){
toDecimal();
}
void toBinary(){
binaryString = "";
int temp = decimalNo;
while(temp > 0){
binaryString = char(temp%2 + '0') + binaryString;
temp /= 2;
}
}
void toDecimal(){
decimalNo = 0;
for(int i=0;i<binaryString.length();i++) decimalNo += (binaryString[i] - '0')*pow(2, binaryString.length()-1-i);
}
// Overloading + operator for addition
Binary operator+(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo + other.decimalNo;
result.toBinary();
return result;
}
// Overloading - operator for subtraction
Binary operator-(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo - other.decimalNo;
result.toBinary();
return result;
}
// Overloading += operator for addition
Binary& operator+=(const Binary& other){
this->decimalNo += other.decimalNo;
this->toBinary();
return *this;
}
// Overloading -= operator for subtraction
Binary& operator-=(const Binary& other){
this->decimalNo -= other.decimalNo;
this->toBinary();
return *this;
}
// Overloading * operator for multiplication (Convert to base 10 multiply and convert back into base 2)
Binary operator*(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo * other.decimalNo;
result.toBinary();
return result;
}
// Overloading / operator for division (Convert to base 10 divide and convert back into base 2)
Binary operator/(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo / other.decimalNo;
result.toBinary();
return result;
}
// Overloading % operator for modulus (Convert to base 10 modulus and convert back into base 2)
Binary operator%(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo % other.decimalNo;
result.toBinary();
return result;
}
// Overloading | operator for or
Binary operator|(const Binary& other) const{
Binary result("", 2);
// if(this->binaryString.length() < other.binaryString.length()){
// for(int i=0;i<other.binaryString.length() - this->binaryString.length();i++) this->binaryString = '0' + this->binaryString;
// }
// else if(this->binaryString.length() > other.binaryString.length()){
// for(int i=0;i<this->binaryString.length() - other.binaryString.length();i++) other.binaryString = '0' + other.binaryString;
// }
// for(int i=0;i<this->binaryString.length();i++){
// result.binaryString += this->binaryString[i] || other.binaryString[i];
// }
result.decimalNo = this->decimalNo | other.decimalNo;
result.toBinary();
return result;
}
// Overloading ^ operator for xor
Binary operator^(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo ^ other.decimalNo;
result.toBinary();
return result;
}
// Overloading & operator for and
Binary operator&(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo & other.decimalNo;
result.toBinary();
return result;
}
// Overloading ! operator for 2's Compliment
Binary operator!() const{
}
// Overloading ~ operator for 1's Compliment
Binary operator~() const{
}
// Overloading left shift operator
Binary operator<<(int shiftAmount) const{
Binary result("", 2);
result.decimalNo = this->decimalNo << shiftAmount;
result.toBinary();
return result;
}
// Overloading right shift operator
Binary operator>>(int shiftAmount) const{
Binary result("", 2);
result.decimalNo = this->decimalNo >> shiftAmount;
result.toBinary();
return result;
}
// Overloading input operator
friend istream& operator>>(istream& input, Binary& other);
// Overloading output operator (Display Both Binary as well as Integer value)
friend ostream& operator<<(ostream& output, const Binary& other);
};
istream& operator>>(istream& input, Binary& other){
cout<<"Enter binary: ";
input>>other.binaryString;
cout<<"Enter base: ";
input>>other.base;
other.toBinary();
return input;
}
ostream& operator<<(ostream& output, const Binary& other){
cout<<"Binary: ";
output<<other.binaryString<<endl;
cout<<"Decimal value: ";
output<<other.decimalNo<<endl;
cout<<"Base: ";
output<<other.base<<endl;
}

View file

@ -0,0 +1,175 @@
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
class Binary {
private:
string binaryString;
int base;
int decimalNo;
public:
// Constructor (If base is greater than 2 first convert into base 10 using that base and then convert back into binary and change the base to 2)
Binary(string binaryStr, int base = 2){
toDecimal();
}
void toBinary(){
binaryString = "";
int temp = decimalNo;
while(temp > 0){
binaryString = char(temp%2 + '0') + binaryString;
temp /= 2;
}
}
void toDecimal(){
decimalNo = 0;
for(int i=0;i<binaryString.length();i++) decimalNo += (binaryString[i] - '0')*pow(2, binaryString.length()-1-i);
}
// Overloading + operator for addition
Binary operator+(const Binary& other) const{
Binary result("");
result.decimalNo = this->decimalNo + other.decimalNo;
result.toBinary();
return result;
}
// Overloading - operator for subtraction
Binary operator-(const Binary& other) const{
Binary result("");
result.decimalNo = this->decimalNo - other.decimalNo;
result.toBinary();
return result;
}
// Overloading += operator for addition
Binary& operator+=(const Binary& other){
this->decimalNo += other.decimalNo;
this->toBinary();
return *this;
}
// Overloading -= operator for subtraction
Binary& operator-=(const Binary& other){
this->decimalNo -= other.decimalNo;
this->toBinary();
return *this;
}
// Overloading * operator for multiplication (Convert to base 10 multiply and convert back into base 2)
Binary operator*(const Binary& other) const{
Binary result("");
result.decimalNo = this->decimalNo * other.decimalNo;
result.toBinary();
return result;
}
// Overloading / operator for division (Convert to base 10 divide and convert back into base 2)
Binary operator/(const Binary& other) const{
Binary result("");
result.decimalNo = this->decimalNo / other.decimalNo;
result.toBinary();
return result;
}
// Overloading % operator for modulus (Convert to base 10 modulus and convert back into base 2)
Binary operator%(const Binary& other) const{
Binary result("");
result.decimalNo = this->decimalNo % other.decimalNo;
result.toBinary();
return result;
}
// Overloading | operator for or
Binary operator|(const Binary& other) const{
Binary result("");
// if(this->binaryString.length() < other.binaryString.length()){
// for(int i=0;i<other.binaryString.length() - this->binaryString.length();i++) this->binaryString = '0' + this->binaryString;
// }
// else if(this->binaryString.length() > other.binaryString.length()){
// for(int i=0;i<this->binaryString.length() - other.binaryString.length();i++) other.binaryString = '0' + other.binaryString;
// }
// for(int i=0;i<this->binaryString.length();i++){
// result.binaryString += this->binaryString[i] || other.binaryString[i];
// }
result.decimalNo = this->decimalNo | other.decimalNo;
result.toBinary();
return result;
}
// Overloading ^ operator for xor
Binary operator^(const Binary& other) const{
Binary result("");
result.decimalNo = this->decimalNo ^ other.decimalNo;
result.toBinary();
return result;
}
// Overloading & operator for and
Binary operator&(const Binary& other) const{
Binary result("");
result.decimalNo = this->decimalNo & other.decimalNo;
result.toBinary();
return result;
}
// Overloading ! operator for 2's Compliment
Binary operator!() const{
}
// Overloading ~ operator for 1's Compliment
Binary operator~() const{
Binary result("");
result.decimalNo = ~this->decimalNo;
result.toBinary();
return result;
}
// Overloading left shift operator
Binary operator<<(int shiftAmount) const{
Binary result("");
result.decimalNo = this->decimalNo << shiftAmount;
result.toBinary();
return result;
}
// Overloading right shift operator
Binary operator>>(int shiftAmount) const{
Binary result("");
result.decimalNo = this->decimalNo >> shiftAmount;
result.toBinary();
return result;
}
// Overloading input operator
friend istream& operator>>(istream& input, Binary& other);
// Overloading output operator (Display Both Binary as well as Integer value)
friend ostream& operator<<(ostream& output, const Binary& other);
};
istream& operator>>(istream& input, Binary& other){
cout<<"Enter binary: ";
input>>other.binaryString;
cout<<"Enter base: ";
input>>other.base;
other.toBinary();
return input;
}
ostream& operator<<(ostream& output, const Binary& other){
cout<<"Binary: ";
output<<other.binaryString<<endl;
cout<<"Decimal value: ";
output<<other.decimalNo<<endl;
cout<<"Base: ";
output<<other.base<<endl;
}

View file

@ -0,0 +1,142 @@
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
class Binary {
private:
string binaryString;
int base;
int decimalNo;
public:
// Constructor (If base is greater than 2 first convert into base 10 using that base and then convert back into binary and change the base to 2)
Binary(string binaryStr, int base = 2){
toDecimal();
}
void toBinary(){
binaryString = "";
int temp = decimalNo;
while(temp > 0){
binaryString = char(temp%2 + '0') + binaryString;
temp /= 2;
}
}
void toDecimal(){
decimalNo = 0;
for(int i=0;i<binaryString.length();i++) decimalNo += (binaryString[i] - '0')*pow(2, binaryString.length()-1-i);
}
// Overloading + operator for addition
Binary operator+(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo + other.decimalNo;
result.toBinary();
return result;
}
// Overloading - operator for subtraction
Binary operator-(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo - other.decimalNo;
result.toBinary();
return result;
}
// Overloading += operator for addition
Binary& operator+=(const Binary& other){
this->decimalNo += other.decimalNo;
this->toBinary();
return *this;
}
// Overloading -= operator for subtraction
Binary& operator-=(const Binary& other){
this->decimalNo -= other.decimalNo;
this->toBinary();
return *this;
}
// Overloading * operator for multiplication (Convert to base 10 multiply and convert back into base 2)
Binary operator*(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo * other.decimalNo;
result.toBinary();
return result;
}
// Overloading / operator for division (Convert to base 10 divide and convert back into base 2)
Binary operator/(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo / other.decimalNo;
result.toBinary();
return result;
}
// Overloading % operator for modulus (Convert to base 10 modulus and convert back into base 2)
Binary operator%(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo % other.decimalNo;
result.toBinary();
return result;
}
// Overloading | operator for or
Binary operator|(Binary& other){
Binary result("", 2);
if(this->binaryString.length() < other.binaryString.length()){
for(int i=0;i<other.binaryString.length() - this->binaryString.length();i++) this->binaryString = '0' + this->binaryString;
}
else if(this->binaryString.length() > other.binaryString.length()){
for(int i=0;i<this->binaryString.length() - other.binaryString.length();i++) other.binaryString = '0' + other.binaryString;
}
for(int i=0;i<this->binaryString.length();i++){
result.binaryString += this->binaryString[i] || other.binaryString[i];
}
}
// Overloading ^ operator for xor
Binary operator^(const Binary& other) const{
}
// Overloading & operator for and
Binary operator&(const Binary& other) const{
}
// Overloading ! operator for 2's Compliment
Binary operator!() const{
}
// Overloading ~ operator for 1's Compliment
Binary operator~() const{
}
// Overloading left shift operator
Binary operator<<(int shiftAmount) const{
}
// Overloading right shift operator
Binary operator>>(int shiftAmount) const{
}
// Overloading input operator
friend istream& operator>>(istream& input, Binary& other){
}
// Overloading output operator (Display Both Binary as well as Integer value)
friend ostream& operator<<(ostream& output, const Binary& other){
}
};

View file

@ -0,0 +1,137 @@
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
class Binary {
private:
string binaryString;
int base;
int decimalNo;
public:
// Constructor (If base is greater than 2 first convert into base 10 using that base and then convert back into binary and change the base to 2)
Binary(string binaryStr, int base = 2){
toDecimal();
}
void toBinary(){
binaryString = "";
int temp = decimalNo;
while(temp > 0){
binaryString = char(temp%2 + '0') + binaryString;
temp /= 2;
}
}
void toDecimal(){
decimalNo = 0;
for(int i=0;i<binaryString.length();i++) decimalNo += (binaryString[i] - '0')*pow(2, binaryString.length()-1-i);
}
// Overloading + operator for addition
Binary operator+(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo + other.decimalNo;
result.toBinary();
return result;
}
// Overloading - operator for subtraction
Binary operator-(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo - other.decimalNo;
result.toBinary();
return result;
}
// Overloading += operator for addition
Binary& operator+=(const Binary& other){
this->decimalNo += other.decimalNo;
this->toBinary();
return *this;
}
// Overloading -= operator for subtraction
Binary& operator-=(const Binary& other){
this->decimalNo -= other.decimalNo;
this->toBinary();
return *this;
}
// Overloading * operator for multiplication (Convert to base 10 multiply and convert back into base 2)
Binary operator*(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo * other.decimalNo;
result.toBinary();
return result;
}
// Overloading / operator for division (Convert to base 10 divide and convert back into base 2)
Binary operator/(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo / other.decimalNo;
result.toBinary();
return result;
}
// Overloading % operator for modulus (Convert to base 10 modulus and convert back into base 2)
Binary operator%(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo % other.decimalNo;
result.toBinary();
return result;
}
// Overloading | operator for or
Binary operator|(const Binary& other) const{
Binary("", 2);
if(this->binaryString.length() < other.binaryString.length()){
for(int i=0;i<other.binaryString.length() - this->binaryString.length();i++){
this->binaryString = '0' + this->binaryString;
}
}
}
// Overloading ^ operator for xor
Binary operator^(const Binary& other) const{
}
// Overloading & operator for and
Binary operator&(const Binary& other) const{
}
// Overloading ! operator for 2's Compliment
Binary operator!() const{
}
// Overloading ~ operator for 1's Compliment
Binary operator~() const{
}
// Overloading left shift operator
Binary operator<<(int shiftAmount) const{
}
// Overloading right shift operator
Binary operator>>(int shiftAmount) const{
}
// Overloading input operator
friend istream& operator>>(istream& input, Binary& other){
}
// Overloading output operator (Display Both Binary as well as Integer value)
friend ostream& operator<<(ostream& output, const Binary& other){
}
};

View file

@ -0,0 +1,175 @@
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
class Binary {
private:
string binaryString;
int base;
int decimalNo;
public:
// Constructor (If base is greater than 2 first convert into base 10 using that base and then convert back into binary and change the base to 2)
Binary(string binaryStr, int base = 2){
toDecimal();
}
void toBinary(){
binaryString = "";
int temp = decimalNo;
while(temp > 0){
binaryString = char(temp%2 + '0') + binaryString;
temp /= 2;
}
}
void toDecimal(){
decimalNo = 0;
for(int i=0;i<binaryString.length();i++) decimalNo += (binaryString[i] - '0')*pow(2, binaryString.length()-1-i);
}
// Overloading + operator for addition
Binary operator+(const Binary& other) const{
Binary result("");
result.decimalNo = this->decimalNo + other.decimalNo;
result.toBinary();
return result;
}
// Overloading - operator for subtraction
Binary operator-(const Binary& other) const{
Binary result("");
result.decimalNo = this->decimalNo - other.decimalNo;
result.toBinary();
return result;
}
// Overloading += operator for addition
Binary& operator+=(const Binary& other){
this->decimalNo += other.decimalNo;
this->toBinary();
return *this;
}
// Overloading -= operator for subtraction
Binary& operator-=(const Binary& other){
this->decimalNo -= other.decimalNo;
this->toBinary();
return *this;
}
// Overloading * operator for multiplication (Convert to base 10 multiply and convert back into base 2)
Binary operator*(const Binary& other) const{
Binary result("");
result.decimalNo = this->decimalNo * other.decimalNo;
result.toBinary();
return result;
}
// Overloading / operator for division (Convert to base 10 divide and convert back into base 2)
Binary operator/(const Binary& other) const{
Binary result("");
result.decimalNo = this->decimalNo / other.decimalNo;
result.toBinary();
return result;
}
// Overloading % operator for modulus (Convert to base 10 modulus and convert back into base 2)
Binary operator%(const Binary& other) const{
Binary result("");
result.decimalNo = this->decimalNo % other.decimalNo;
result.toBinary();
return result;
}
// Overloading | operator for or
Binary operator|(const Binary& other) const{
Binary result("");
// if(this->binaryString.length() < other.binaryString.length()){
// for(int i=0;i<other.binaryString.length() - this->binaryString.length();i++) this->binaryString = '0' + this->binaryString;
// }
// else if(this->binaryString.length() > other.binaryString.length()){
// for(int i=0;i<this->binaryString.length() - other.binaryString.length();i++) other.binaryString = '0' + other.binaryString;
// }
// for(int i=0;i<this->binaryString.length();i++){
// result.binaryString += this->binaryString[i] || other.binaryString[i];
// }
result.decimalNo = this->decimalNo | other.decimalNo;
result.toBinary();
return result;
}
// Overloading ^ operator for xor
Binary operator^(const Binary& other) const{
Binary result("");
result.decimalNo = this->decimalNo ^ other.decimalNo;
result.toBinary();
return result;
}
// Overloading & operator for and
Binary operator&(const Binary& other) const{
Binary result("");
result.decimalNo = this->decimalNo & other.decimalNo;
result.toBinary();
return result;
}
// Overloading ! operator for 2's Compliment
Binary operator!() const{
}
// Overloading ~ operator for 1's Compliment
Binary operator~() const{
for(int i=0;i<this->binaryString.length();i++){
}
}
// Overloading left shift operator
Binary operator<<(int shiftAmount) const{
Binary result("");
result.decimalNo = this->decimalNo << shiftAmount;
result.toBinary();
return result;
}
// Overloading right shift operator
Binary operator>>(int shiftAmount) const{
Binary result("");
result.decimalNo = this->decimalNo >> shiftAmount;
result.toBinary();
return result;
}
// Overloading input operator
friend istream& operator>>(istream& input, Binary& other);
// Overloading output operator (Display Both Binary as well as Integer value)
friend ostream& operator<<(ostream& output, const Binary& other);
};
istream& operator>>(istream& input, Binary& other){
cout<<"Enter binary: ";
input>>other.binaryString;
cout<<"Enter base: ";
input>>other.base;
other.toBinary();
return input;
}
ostream& operator<<(ostream& output, const Binary& other){
cout<<"Binary: ";
output<<other.binaryString<<endl;
cout<<"Decimal value: ";
output<<other.decimalNo<<endl;
cout<<"Base: ";
output<<other.base<<endl;
}

View file

@ -0,0 +1,115 @@
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
class Binary {
private:
string binaryString;
int base;
int decimalNo;
public:
// Constructor (If base is greater than 2 first convert into base 10 using that base and then convert back into binary and change the base to 2)
Binary(string binaryStr, int base = 2){
if(base > 2){
}
}
void toBinary(){
binaryString = "";
int temp = decimalNo;
while(temp > 0){
binaryString = char(temp%2 + '0') + binaryString;
temp /= 2;
}
}
void toDecimal(){
decimalNo = 0;
for(int i=binaryString.length()-1;i>=0;i++) decimalNo += (binaryString[i] - '0')*pow(2, i);
}
// Overloading + operator for addition
Binary operator+(const Binary& other) const{
}
// Overloading - operator for subtraction
Binary operator-(const Binary& other) const{
}
// Overloading += operator for addition
Binary& operator+=(const Binary& other) const{
}
// Overloading -= operator for subtraction
Binary& operator-=(const Binary& other) const{
}
// Overloading * operator for multiplication (Convert to base 10 multiply and convert back into base 2)
Binary operator*(const Binary& other) const{
}
// Overloading / operator for division (Convert to base 10 divide and convert back into base 2)
Binary operator/(const Binary& other) const{
}
// Overloading % operator for modulus (Convert to base 10 modulus and convert back into base 2)
Binary operator%(const Binary& other) const{
}
// Overloading | operator for or
Binary operator|(const Binary& other) const{
}
// Overloading ^ operator for xor
Binary operator^(const Binary& other) const{
}
// Overloading & operator for and
Binary operator&(const Binary& other) const{
}
// Overloading ! operator for 2's Compliment
Binary operator!() const{
}
// Overloading ~ operator for 1's Compliment
Binary operator~() const{
}
// Overloading left shift operator
Binary operator<<(int shiftAmount) const{
}
// Overloading right shift operator
Binary operator>>(int shiftAmount) const{
}
// Overloading input operator
friend istream& operator>>(istream& input, Binary& other){
}
// Overloading output operator (Display Both Binary as well as Integer value)
friend ostream& operator<<(ostream& output, const Binary& other){
}
};

View file

@ -0,0 +1,178 @@
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
class Binary {
private:
string binaryString;
int base;
int decimalNo;
public:
// Constructor (If base is greater than 2 first convert into base 10 using that base and then convert back into binary and change the base to 2)
Binary(string binaryStr, int base = 2){
toDecimal();
}
void toBinary(){
binaryString = "";
int temp = decimalNo;
while(temp > 0){
binaryString = char(temp%2 + '0') + binaryString;
temp /= 2;
}
}
void toDecimal(){
decimalNo = 0;
for(int i=0;i<binaryString.length();i++) decimalNo += (binaryString[i] - '0')*pow(2, binaryString.length()-1-i);
}
// Overloading + operator for addition
Binary operator+(const Binary& other) const{
Binary result("");
result.decimalNo = this->decimalNo + other.decimalNo;
result.toBinary();
return result;
}
// Overloading - operator for subtraction
Binary operator-(const Binary& other) const{
Binary result("");
result.decimalNo = this->decimalNo - other.decimalNo;
result.toBinary();
return result;
}
// Overloading += operator for addition
Binary& operator+=(const Binary& other){
this->decimalNo += other.decimalNo;
this->toBinary();
return *this;
}
// Overloading -= operator for subtraction
Binary& operator-=(const Binary& other){
this->decimalNo -= other.decimalNo;
this->toBinary();
return *this;
}
// Overloading * operator for multiplication (Convert to base 10 multiply and convert back into base 2)
Binary operator*(const Binary& other) const{
Binary result("");
result.decimalNo = this->decimalNo * other.decimalNo;
result.toBinary();
return result;
}
// Overloading / operator for division (Convert to base 10 divide and convert back into base 2)
Binary operator/(const Binary& other) const{
Binary result("");
result.decimalNo = this->decimalNo / other.decimalNo;
result.toBinary();
return result;
}
// Overloading % operator for modulus (Convert to base 10 modulus and convert back into base 2)
Binary operator%(const Binary& other) const{
Binary result("");
result.decimalNo = this->decimalNo % other.decimalNo;
result.toBinary();
return result;
}
// Overloading | operator for or
Binary operator|(const Binary& other) const{
Binary result("");
// if(this->binaryString.length() < other.binaryString.length()){
// for(int i=0;i<other.binaryString.length() - this->binaryString.length();i++) this->binaryString = '0' + this->binaryString;
// }
// else if(this->binaryString.length() > other.binaryString.length()){
// for(int i=0;i<this->binaryString.length() - other.binaryString.length();i++) other.binaryString = '0' + other.binaryString;
// }
// for(int i=0;i<this->binaryString.length();i++){
// result.binaryString += this->binaryString[i] || other.binaryString[i];
// }
result.decimalNo = this->decimalNo | other.decimalNo;
result.toBinary();
return result;
}
// Overloading ^ operator for xor
Binary operator^(const Binary& other) const{
Binary result("");
result.decimalNo = this->decimalNo ^ other.decimalNo;
result.toBinary();
return result;
}
// Overloading & operator for and
Binary operator&(const Binary& other) const{
Binary result("");
result.decimalNo = this->decimalNo & other.decimalNo;
result.toBinary();
return result;
}
// Overloading ! operator for 2's Compliment
Binary operator!() const{
Binary result("");
result.decimalNo = ~this->decimalNo + 1; // 2's complement is 1's complement + 1
result.toBinary();
return result;
}
// Overloading ~ operator for 1's Compliment
Binary operator~() const{
Binary result("");
result.decimalNo = ~this->decimalNo;
result.toBinary();
return result;
}
// Overloading left shift operator
Binary operator<<(int shiftAmount) const{
Binary result("");
result.decimalNo = this->decimalNo << shiftAmount;
result.toBinary();
return result;
}
// Overloading right shift operator
Binary operator>>(int shiftAmount) const{
Binary result("");
result.decimalNo = this->decimalNo >> shiftAmount;
result.toBinary();
return result;
}
// Overloading input operator
friend istream& operator>>(istream& input, Binary& other);
// Overloading output operator (Display Both Binary as well as Integer value)
friend ostream& operator<<(ostream& output, const Binary& other);
};
istream& operator>>(istream& input, Binary& other){
cout<<"Enter binary: ";
input>>other.binaryString;
cout<<"Enter base: ";
input>>other.base;
other.toBinary();
return input;
}
ostream& operator<<(ostream& output, const Binary& other){
cout<<"Binary: ";
output<<other.binaryString<<endl;
cout<<"Decimal value: ";
output<<other.decimalNo<<endl;
cout<<"Base: ";
output<<other.base<<endl;
}

View file

@ -0,0 +1,166 @@
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
class Binary {
private:
string binaryString;
int base;
int decimalNo;
public:
// Constructor (If base is greater than 2 first convert into base 10 using that base and then convert back into binary and change the base to 2)
Binary(string binaryStr, int base = 2){
toDecimal();
}
void toBinary(){
binaryString = "";
int temp = decimalNo;
while(temp > 0){
binaryString = char(temp%2 + '0') + binaryString;
temp /= 2;
}
}
void toDecimal(){
decimalNo = 0;
for(int i=0;i<binaryString.length();i++) decimalNo += (binaryString[i] - '0')*pow(2, binaryString.length()-1-i);
}
// Overloading + operator for addition
Binary operator+(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo + other.decimalNo;
result.toBinary();
return result;
}
// Overloading - operator for subtraction
Binary operator-(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo - other.decimalNo;
result.toBinary();
return result;
}
// Overloading += operator for addition
Binary& operator+=(const Binary& other){
this->decimalNo += other.decimalNo;
this->toBinary();
return *this;
}
// Overloading -= operator for subtraction
Binary& operator-=(const Binary& other){
this->decimalNo -= other.decimalNo;
this->toBinary();
return *this;
}
// Overloading * operator for multiplication (Convert to base 10 multiply and convert back into base 2)
Binary operator*(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo * other.decimalNo;
result.toBinary();
return result;
}
// Overloading / operator for division (Convert to base 10 divide and convert back into base 2)
Binary operator/(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo / other.decimalNo;
result.toBinary();
return result;
}
// Overloading % operator for modulus (Convert to base 10 modulus and convert back into base 2)
Binary operator%(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo % other.decimalNo;
result.toBinary();
return result;
}
// Overloading | operator for or
Binary operator|(const Binary& other) const{
Binary result("", 2);
// if(this->binaryString.length() < other.binaryString.length()){
// for(int i=0;i<other.binaryString.length() - this->binaryString.length();i++) this->binaryString = '0' + this->binaryString;
// }
// else if(this->binaryString.length() > other.binaryString.length()){
// for(int i=0;i<this->binaryString.length() - other.binaryString.length();i++) other.binaryString = '0' + other.binaryString;
// }
// for(int i=0;i<this->binaryString.length();i++){
// result.binaryString += this->binaryString[i] || other.binaryString[i];
// }
result.decimalNo = this->decimalNo | other.decimalNo;
result.toBinary();
return result;
}
// Overloading ^ operator for xor
Binary operator^(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo ^ other.decimalNo;
result.toBinary();
return result;
}
// Overloading & operator for and
Binary operator&(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo & other.decimalNo;
result.toBinary();
return result;
}
// Overloading ! operator for 2's Compliment
Binary operator!() const{
}
// Overloading ~ operator for 1's Compliment
Binary operator~() const{
}
// Overloading left shift operator
Binary operator<<(int shiftAmount) const{
Binary result("", 2);
result.decimalNo = this->decimalNo << shiftAmount;
result.toBinary();
return result;
}
// Overloading right shift operator
Binary operator>>(int shiftAmount) const{
Binary result("", 2);
result.decimalNo = this->decimalNo >> shiftAmount;
result.toBinary();
return result;
}
// Overloading input operator
friend istream& operator>>(istream& input, Binary& other);
// Overloading output operator (Display Both Binary as well as Integer value)
friend ostream& operator<<(ostream& output, const Binary& other);
};
istream& operator>>(istream& input, Binary& other){
cout<<"Enter binary: ";
input>>other.binaryString;
cout<<"Enter base: ";
input>>other.base;
other.toBinary();
}
ostream& operator<<(ostream& output, const Binary& other){
}

View file

@ -0,0 +1,113 @@
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
class Binary {
private:
string binaryString;
int base;
int decimalNo;
public:
// Constructor (If base is greater than 2 first convert into base 10 using that base and then convert back into binary and change the base to 2)
Binary(string binaryStr, int base = 2){
toDecimal();
}
void toBinary(){
binaryString = "";
int temp = decimalNo;
while(temp > 0){
binaryString = char(temp%2 + '0') + binaryString;
temp /= 2;
}
}
void toDecimal(){
decimalNo = 0;
for(int i=0;i<binaryString.length();i++) decimalNo += (binaryString[i] - '0')*pow(2, binaryString.length()-1-i);
}
// Overloading + operator for addition
Binary operator+(const Binary& other) const{
}
// Overloading - operator for subtraction
Binary operator-(const Binary& other) const{
}
// Overloading += operator for addition
Binary& operator+=(const Binary& other) const{
}
// Overloading -= operator for subtraction
Binary& operator-=(const Binary& other) const{
}
// Overloading * operator for multiplication (Convert to base 10 multiply and convert back into base 2)
Binary operator*(const Binary& other) const{
}
// Overloading / operator for division (Convert to base 10 divide and convert back into base 2)
Binary operator/(const Binary& other) const{
}
// Overloading % operator for modulus (Convert to base 10 modulus and convert back into base 2)
Binary operator%(const Binary& other) const{
}
// Overloading | operator for or
Binary operator|(const Binary& other) const{
}
// Overloading ^ operator for xor
Binary operator^(const Binary& other) const{
}
// Overloading & operator for and
Binary operator&(const Binary& other) const{
}
// Overloading ! operator for 2's Compliment
Binary operator!() const{
}
// Overloading ~ operator for 1's Compliment
Binary operator~() const{
}
// Overloading left shift operator
Binary operator<<(int shiftAmount) const{
}
// Overloading right shift operator
Binary operator>>(int shiftAmount) const{
}
// Overloading input operator
friend istream& operator>>(istream& input, Binary& other){
}
// Overloading output operator (Display Both Binary as well as Integer value)
friend ostream& operator<<(ostream& output, const Binary& other){
}
};

View file

@ -0,0 +1,142 @@
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
class Binary {
private:
string binaryString;
int base;
int decimalNo;
public:
// Constructor (If base is greater than 2 first convert into base 10 using that base and then convert back into binary and change the base to 2)
Binary(string binaryStr, int base = 2){
toDecimal();
}
void toBinary(){
binaryString = "";
int temp = decimalNo;
while(temp > 0){
binaryString = char(temp%2 + '0') + binaryString;
temp /= 2;
}
}
void toDecimal(){
decimalNo = 0;
for(int i=0;i<binaryString.length();i++) decimalNo += (binaryString[i] - '0')*pow(2, binaryString.length()-1-i);
}
// Overloading + operator for addition
Binary operator+(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo + other.decimalNo;
result.toBinary();
return result;
}
// Overloading - operator for subtraction
Binary operator-(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo - other.decimalNo;
result.toBinary();
return result;
}
// Overloading += operator for addition
Binary& operator+=(const Binary& other){
this->decimalNo += other.decimalNo;
this->toBinary();
return *this;
}
// Overloading -= operator for subtraction
Binary& operator-=(const Binary& other){
this->decimalNo -= other.decimalNo;
this->toBinary();
return *this;
}
// Overloading * operator for multiplication (Convert to base 10 multiply and convert back into base 2)
Binary operator*(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo * other.decimalNo;
result.toBinary();
return result;
}
// Overloading / operator for division (Convert to base 10 divide and convert back into base 2)
Binary operator/(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo / other.decimalNo;
result.toBinary();
return result;
}
// Overloading % operator for modulus (Convert to base 10 modulus and convert back into base 2)
Binary operator%(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo % other.decimalNo;
result.toBinary();
return result;
}
// Overloading | operator for or
Binary operator|(Binary& other){
Binary result("", 2);
if(this->binaryString.length() < other.binaryString.length()){
for(int i=0;i<other.binaryString.length() - this->binaryString.length();i++) this->binaryString = '0' + this->binaryString;
}
else if(this->binaryString.length() > other.binaryString.length()){
for(int i=0;i<this->binaryString.length() - other.binaryString.length();i++) other.binaryString = '0' + other.binaryString;
}
for(int i=0;i<this->binaryString.length();i++){
result.binaryString += this->binaryString[i] | other.binaryString[i];
}
}
// Overloading ^ operator for xor
Binary operator^(const Binary& other) const{
}
// Overloading & operator for and
Binary operator&(const Binary& other) const{
}
// Overloading ! operator for 2's Compliment
Binary operator!() const{
}
// Overloading ~ operator for 1's Compliment
Binary operator~() const{
}
// Overloading left shift operator
Binary operator<<(int shiftAmount) const{
}
// Overloading right shift operator
Binary operator>>(int shiftAmount) const{
}
// Overloading input operator
friend istream& operator>>(istream& input, Binary& other){
}
// Overloading output operator (Display Both Binary as well as Integer value)
friend ostream& operator<<(ostream& output, const Binary& other){
}
};

View file

@ -0,0 +1,126 @@
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
class Binary {
private:
string binaryString;
int base;
int decimalNo;
public:
// Constructor (If base is greater than 2 first convert into base 10 using that base and then convert back into binary and change the base to 2)
Binary(string binaryStr, int base = 2){
toDecimal();
}
void toBinary(){
binaryString = "";
int temp = decimalNo;
while(temp > 0){
binaryString = char(temp%2 + '0') + binaryString;
temp /= 2;
}
}
void toDecimal(){
decimalNo = 0;
for(int i=0;i<binaryString.length();i++) decimalNo += (binaryString[i] - '0')*pow(2, binaryString.length()-1-i);
}
// Overloading + operator for addition
Binary operator+(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo + other.decimalNo;
result.toBinary();
return result;
}
// Overloading - operator for subtraction
Binary operator-(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo - other.decimalNo;
result.toBinary();
return result;
}
// Overloading += operator for addition
Binary& operator+=(const Binary& other){
this->decimalNo += other.decimalNo;
this->toBinary();
return *this;
}
// Overloading -= operator for subtraction
Binary& operator-=(const Binary& other){
this->decimalNo -= other.decimalNo;
this->toBinary();
return *this;
}
// Overloading * operator for multiplication (Convert to base 10 multiply and convert back into base 2)
Binary operator*(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo * other.decimalNo;
result.toBinary();
return result;
}
// Overloading / operator for division (Convert to base 10 divide and convert back into base 2)
Binary operator/(const Binary& other) const{
}
// Overloading % operator for modulus (Convert to base 10 modulus and convert back into base 2)
Binary operator%(const Binary& other) const{
}
// Overloading | operator for or
Binary operator|(const Binary& other) const{
}
// Overloading ^ operator for xor
Binary operator^(const Binary& other) const{
}
// Overloading & operator for and
Binary operator&(const Binary& other) const{
}
// Overloading ! operator for 2's Compliment
Binary operator!() const{
}
// Overloading ~ operator for 1's Compliment
Binary operator~() const{
}
// Overloading left shift operator
Binary operator<<(int shiftAmount) const{
}
// Overloading right shift operator
Binary operator>>(int shiftAmount) const{
}
// Overloading input operator
friend istream& operator>>(istream& input, Binary& other){
}
// Overloading output operator (Display Both Binary as well as Integer value)
friend ostream& operator<<(ostream& output, const Binary& other){
}
};

View file

@ -0,0 +1,137 @@
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
class Binary {
private:
string binaryString;
int base;
int decimalNo;
public:
// Constructor (If base is greater than 2 first convert into base 10 using that base and then convert back into binary and change the base to 2)
Binary(string binaryStr, int base = 2){
toDecimal();
}
void toBinary(){
binaryString = "";
int temp = decimalNo;
while(temp > 0){
binaryString = char(temp%2 + '0') + binaryString;
temp /= 2;
}
}
void toDecimal(){
decimalNo = 0;
for(int i=0;i<binaryString.length();i++) decimalNo += (binaryString[i] - '0')*pow(2, binaryString.length()-1-i);
}
// Overloading + operator for addition
Binary operator+(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo + other.decimalNo;
result.toBinary();
return result;
}
// Overloading - operator for subtraction
Binary operator-(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo - other.decimalNo;
result.toBinary();
return result;
}
// Overloading += operator for addition
Binary& operator+=(const Binary& other){
this->decimalNo += other.decimalNo;
this->toBinary();
return *this;
}
// Overloading -= operator for subtraction
Binary& operator-=(const Binary& other){
this->decimalNo -= other.decimalNo;
this->toBinary();
return *this;
}
// Overloading * operator for multiplication (Convert to base 10 multiply and convert back into base 2)
Binary operator*(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo * other.decimalNo;
result.toBinary();
return result;
}
// Overloading / operator for division (Convert to base 10 divide and convert back into base 2)
Binary operator/(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo / other.decimalNo;
result.toBinary();
return result;
}
// Overloading % operator for modulus (Convert to base 10 modulus and convert back into base 2)
Binary operator%(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo % other.decimalNo;
result.toBinary();
return result;
}
// Overloading | operator for or
Binary operator|(const Binary& other){
Binary("", 2);
if(this->binaryString.length() < other.binaryString.length()){
for(int i=0;i<other.binaryString.length() - this->binaryString.length();i++){
this->binaryString = '0' + this->binaryString;
}
}
}
// Overloading ^ operator for xor
Binary operator^(const Binary& other) const{
}
// Overloading & operator for and
Binary operator&(const Binary& other) const{
}
// Overloading ! operator for 2's Compliment
Binary operator!() const{
}
// Overloading ~ operator for 1's Compliment
Binary operator~() const{
}
// Overloading left shift operator
Binary operator<<(int shiftAmount) const{
}
// Overloading right shift operator
Binary operator>>(int shiftAmount) const{
}
// Overloading input operator
friend istream& operator>>(istream& input, Binary& other){
}
// Overloading output operator (Display Both Binary as well as Integer value)
friend ostream& operator<<(ostream& output, const Binary& other){
}
};

View file

@ -0,0 +1,142 @@
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
class Binary {
private:
string binaryString;
int base;
int decimalNo;
public:
// Constructor (If base is greater than 2 first convert into base 10 using that base and then convert back into binary and change the base to 2)
Binary(string binaryStr, int base = 2){
toDecimal();
}
void toBinary(){
binaryString = "";
int temp = decimalNo;
while(temp > 0){
binaryString = char(temp%2 + '0') + binaryString;
temp /= 2;
}
}
void toDecimal(){
decimalNo = 0;
for(int i=0;i<binaryString.length();i++) decimalNo += (binaryString[i] - '0')*pow(2, binaryString.length()-1-i);
}
// Overloading + operator for addition
Binary operator+(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo + other.decimalNo;
result.toBinary();
return result;
}
// Overloading - operator for subtraction
Binary operator-(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo - other.decimalNo;
result.toBinary();
return result;
}
// Overloading += operator for addition
Binary& operator+=(const Binary& other){
this->decimalNo += other.decimalNo;
this->toBinary();
return *this;
}
// Overloading -= operator for subtraction
Binary& operator-=(const Binary& other){
this->decimalNo -= other.decimalNo;
this->toBinary();
return *this;
}
// Overloading * operator for multiplication (Convert to base 10 multiply and convert back into base 2)
Binary operator*(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo * other.decimalNo;
result.toBinary();
return result;
}
// Overloading / operator for division (Convert to base 10 divide and convert back into base 2)
Binary operator/(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo / other.decimalNo;
result.toBinary();
return result;
}
// Overloading % operator for modulus (Convert to base 10 modulus and convert back into base 2)
Binary operator%(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo % other.decimalNo;
result.toBinary();
return result;
}
// Overloading | operator for or
Binary operator|(Binary& other){
Binary result("", 2);
if(this->binaryString.length() < other.binaryString.length()){
for(int i=0;i<other.binaryString.length() - this->binaryString.length();i++) this->binaryString = '0' + this->binaryString;
}
else if(this->binaryString.length() > other.binaryString.length()){
for(int i=0;i<this->binaryString.length() - other.binaryString.length();i++) other.binaryString = '0' + other.binaryString;
}
for(int i=0;i<this->binaryString.length();i++){
result.binaryString += this->binaryString[i] || other.binaryString[i];
}
}
// Overloading ^ operator for xor
Binary operator^(const Binary& other) const{
}
// Overloading & operator for and
Binary operator&(const Binary& other) const{
}
// Overloading ! operator for 2's Compliment
Binary operator!() const{
}
// Overloading ~ operator for 1's Compliment
Binary operator~() const{
}
// Overloading left shift operator
Binary operator<<(int shiftAmount) const{
}
// Overloading right shift operator
Binary operator>>(int shiftAmount) const{
}
// Overloading input operator
friend istream& operator>>(istream& input, Binary& other){
}
// Overloading output operator (Display Both Binary as well as Integer value)
friend ostream& operator<<(ostream& output, const Binary& other){
}
};

View file

@ -0,0 +1,162 @@
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
class Binary {
private:
string binaryString;
int base;
int decimalNo;
public:
// Constructor (If base is greater than 2 first convert into base 10 using that base and then convert back into binary and change the base to 2)
Binary(string binaryStr, int base = 2){
toDecimal();
}
void toBinary(){
binaryString = "";
int temp = decimalNo;
while(temp > 0){
binaryString = char(temp%2 + '0') + binaryString;
temp /= 2;
}
}
void toDecimal(){
decimalNo = 0;
for(int i=0;i<binaryString.length();i++) decimalNo += (binaryString[i] - '0')*pow(2, binaryString.length()-1-i);
}
// Overloading + operator for addition
Binary operator+(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo + other.decimalNo;
result.toBinary();
return result;
}
// Overloading - operator for subtraction
Binary operator-(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo - other.decimalNo;
result.toBinary();
return result;
}
// Overloading += operator for addition
Binary& operator+=(const Binary& other){
this->decimalNo += other.decimalNo;
this->toBinary();
return *this;
}
// Overloading -= operator for subtraction
Binary& operator-=(const Binary& other){
this->decimalNo -= other.decimalNo;
this->toBinary();
return *this;
}
// Overloading * operator for multiplication (Convert to base 10 multiply and convert back into base 2)
Binary operator*(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo * other.decimalNo;
result.toBinary();
return result;
}
// Overloading / operator for division (Convert to base 10 divide and convert back into base 2)
Binary operator/(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo / other.decimalNo;
result.toBinary();
return result;
}
// Overloading % operator for modulus (Convert to base 10 modulus and convert back into base 2)
Binary operator%(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo % other.decimalNo;
result.toBinary();
return result;
}
// Overloading | operator for or
Binary operator|(const Binary& other) const{
Binary result("", 2);
// if(this->binaryString.length() < other.binaryString.length()){
// for(int i=0;i<other.binaryString.length() - this->binaryString.length();i++) this->binaryString = '0' + this->binaryString;
// }
// else if(this->binaryString.length() > other.binaryString.length()){
// for(int i=0;i<this->binaryString.length() - other.binaryString.length();i++) other.binaryString = '0' + other.binaryString;
// }
// for(int i=0;i<this->binaryString.length();i++){
// result.binaryString += this->binaryString[i] || other.binaryString[i];
// }
result.decimalNo = this->decimalNo | other.decimalNo;
result.toBinary();
return result;
}
// Overloading ^ operator for xor
Binary operator^(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo ^ other.decimalNo;
result.toBinary();
return result;
}
// Overloading & operator for and
Binary operator&(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo & other.decimalNo;
result.toBinary();
return result;
}
// Overloading ! operator for 2's Compliment
Binary operator!() const{
}
// Overloading ~ operator for 1's Compliment
Binary operator~() const{
}
// Overloading left shift operator
Binary operator<<(int shiftAmount) const{
Binary result("", 2);
result.decimalNo = this->decimalNo << shiftAmount;
result.toBinary();
return result;
}
// Overloading right shift operator
Binary operator>>(int shiftAmount) const{
Binary result("", 2);
result.decimalNo = this->decimalNo >> shiftAmount;
result.toBinary();
return result;
}
// Overloading input operator
friend istream& operator>>(istream& input, Binary& other);
// Overloading output operator (Display Both Binary as well as Integer value)
friend ostream& operator<<(ostream& output, const Binary& other);
};
istream& operator>>(istream& input, Binary& other){
}
ostream& operator<<(ostream& output, const Binary& other){
}

View file

@ -0,0 +1,115 @@
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
class Binary {
private:
string binaryString;
int base;
int decimalNo;
public:
// Constructor (If base is greater than 2 first convert into base 10 using that base and then convert back into binary and change the base to 2)
Binary(string binaryStr, int base = 2){
if(base > 2){
}
}
void toBinary(){
binaryString = "";
int temp = decimalNo;
while(temp > 0){
binaryString = char(temp%2 + '0') + binaryString;
temp /= 2;
}
}
void toDecimal(){
decimalNo = 0;
for(int i=0;i<binaryString.length();i++) decimalNo += (binaryString[i] - '0')*pow(2, binaryString.length()-1-i);
}
// Overloading + operator for addition
Binary operator+(const Binary& other) const{
}
// Overloading - operator for subtraction
Binary operator-(const Binary& other) const{
}
// Overloading += operator for addition
Binary& operator+=(const Binary& other) const{
}
// Overloading -= operator for subtraction
Binary& operator-=(const Binary& other) const{
}
// Overloading * operator for multiplication (Convert to base 10 multiply and convert back into base 2)
Binary operator*(const Binary& other) const{
}
// Overloading / operator for division (Convert to base 10 divide and convert back into base 2)
Binary operator/(const Binary& other) const{
}
// Overloading % operator for modulus (Convert to base 10 modulus and convert back into base 2)
Binary operator%(const Binary& other) const{
}
// Overloading | operator for or
Binary operator|(const Binary& other) const{
}
// Overloading ^ operator for xor
Binary operator^(const Binary& other) const{
}
// Overloading & operator for and
Binary operator&(const Binary& other) const{
}
// Overloading ! operator for 2's Compliment
Binary operator!() const{
}
// Overloading ~ operator for 1's Compliment
Binary operator~() const{
}
// Overloading left shift operator
Binary operator<<(int shiftAmount) const{
}
// Overloading right shift operator
Binary operator>>(int shiftAmount) const{
}
// Overloading input operator
friend istream& operator>>(istream& input, Binary& other){
}
// Overloading output operator (Display Both Binary as well as Integer value)
friend ostream& operator<<(ostream& output, const Binary& other){
}
};

View file

@ -0,0 +1,133 @@
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
class Binary {
private:
string binaryString;
int base;
int decimalNo;
public:
// Constructor (If base is greater than 2 first convert into base 10 using that base and then convert back into binary and change the base to 2)
Binary(string binaryStr, int base = 2){
toDecimal();
}
void toBinary(){
binaryString = "";
int temp = decimalNo;
while(temp > 0){
binaryString = char(temp%2 + '0') + binaryString;
temp /= 2;
}
}
void toDecimal(){
decimalNo = 0;
for(int i=0;i<binaryString.length();i++) decimalNo += (binaryString[i] - '0')*pow(2, binaryString.length()-1-i);
}
// Overloading + operator for addition
Binary operator+(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo + other.decimalNo;
result.toBinary();
return result;
}
// Overloading - operator for subtraction
Binary operator-(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo - other.decimalNo;
result.toBinary();
return result;
}
// Overloading += operator for addition
Binary& operator+=(const Binary& other){
this->decimalNo += other.decimalNo;
this->toBinary();
return *this;
}
// Overloading -= operator for subtraction
Binary& operator-=(const Binary& other){
this->decimalNo -= other.decimalNo;
this->toBinary();
return *this;
}
// Overloading * operator for multiplication (Convert to base 10 multiply and convert back into base 2)
Binary operator*(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo * other.decimalNo;
result.toBinary();
return result;
}
// Overloading / operator for division (Convert to base 10 divide and convert back into base 2)
Binary operator/(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo / other.decimalNo;
result.toBinary();
return result;
}
// Overloading % operator for modulus (Convert to base 10 modulus and convert back into base 2)
Binary operator%(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo % other.decimalNo;
result.toBinary();
return result;
}
// Overloading | operator for or
Binary operator|(const Binary& other) const{
Binary("", 2);
}
// Overloading ^ operator for xor
Binary operator^(const Binary& other) const{
}
// Overloading & operator for and
Binary operator&(const Binary& other) const{
}
// Overloading ! operator for 2's Compliment
Binary operator!() const{
}
// Overloading ~ operator for 1's Compliment
Binary operator~() const{
}
// Overloading left shift operator
Binary operator<<(int shiftAmount) const{
}
// Overloading right shift operator
Binary operator>>(int shiftAmount) const{
}
// Overloading input operator
friend istream& operator>>(istream& input, Binary& other){
}
// Overloading output operator (Display Both Binary as well as Integer value)
friend ostream& operator<<(ostream& output, const Binary& other){
}
};

View file

@ -0,0 +1,138 @@
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
class Binary {
private:
string binaryString;
int base;
int decimalNo;
public:
// Constructor (If base is greater than 2 first convert into base 10 using that base and then convert back into binary and change the base to 2)
Binary(string binaryStr, int base = 2){
toDecimal();
}
void toBinary(){
binaryString = "";
int temp = decimalNo;
while(temp > 0){
binaryString = char(temp%2 + '0') + binaryString;
temp /= 2;
}
}
void toDecimal(){
decimalNo = 0;
for(int i=0;i<binaryString.length();i++) decimalNo += (binaryString[i] - '0')*pow(2, binaryString.length()-1-i);
}
// Overloading + operator for addition
Binary operator+(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo + other.decimalNo;
result.toBinary();
return result;
}
// Overloading - operator for subtraction
Binary operator-(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo - other.decimalNo;
result.toBinary();
return result;
}
// Overloading += operator for addition
Binary& operator+=(const Binary& other){
this->decimalNo += other.decimalNo;
this->toBinary();
return *this;
}
// Overloading -= operator for subtraction
Binary& operator-=(const Binary& other){
this->decimalNo -= other.decimalNo;
this->toBinary();
return *this;
}
// Overloading * operator for multiplication (Convert to base 10 multiply and convert back into base 2)
Binary operator*(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo * other.decimalNo;
result.toBinary();
return result;
}
// Overloading / operator for division (Convert to base 10 divide and convert back into base 2)
Binary operator/(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo / other.decimalNo;
result.toBinary();
return result;
}
// Overloading % operator for modulus (Convert to base 10 modulus and convert back into base 2)
Binary operator%(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo % other.decimalNo;
result.toBinary();
return result;
}
// Overloading | operator for or
Binary operator|(Binary& other){
Binary("", 2);
if(this->binaryString.length() < other.binaryString.length()){
for(int i=0;i<other.binaryString.length() - this->binaryString.length();i++) this->binaryString = '0' + this->binaryString;
}
else if(this->binaryString.length() > other.binaryString.length()){
for(int i=0;i<this->binaryString.length() - other.binaryString.length();i++) other.binaryString = '0' + other.binaryString;
}
}
// Overloading ^ operator for xor
Binary operator^(const Binary& other) const{
}
// Overloading & operator for and
Binary operator&(const Binary& other) const{
}
// Overloading ! operator for 2's Compliment
Binary operator!() const{
}
// Overloading ~ operator for 1's Compliment
Binary operator~() const{
}
// Overloading left shift operator
Binary operator<<(int shiftAmount) const{
}
// Overloading right shift operator
Binary operator>>(int shiftAmount) const{
}
// Overloading input operator
friend istream& operator>>(istream& input, Binary& other){
}
// Overloading output operator (Display Both Binary as well as Integer value)
friend ostream& operator<<(ostream& output, const Binary& other){
}
};

View file

@ -0,0 +1,167 @@
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
class Binary {
private:
string binaryString;
int base;
int decimalNo;
public:
// Constructor (If base is greater than 2 first convert into base 10 using that base and then convert back into binary and change the base to 2)
Binary(string binaryStr, int base = 2){
toDecimal();
}
void toBinary(){
binaryString = "";
int temp = decimalNo;
while(temp > 0){
binaryString = char(temp%2 + '0') + binaryString;
temp /= 2;
}
}
void toDecimal(){
decimalNo = 0;
for(int i=0;i<binaryString.length();i++) decimalNo += (binaryString[i] - '0')*pow(2, binaryString.length()-1-i);
}
// Overloading + operator for addition
Binary operator+(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo + other.decimalNo;
result.toBinary();
return result;
}
// Overloading - operator for subtraction
Binary operator-(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo - other.decimalNo;
result.toBinary();
return result;
}
// Overloading += operator for addition
Binary& operator+=(const Binary& other){
this->decimalNo += other.decimalNo;
this->toBinary();
return *this;
}
// Overloading -= operator for subtraction
Binary& operator-=(const Binary& other){
this->decimalNo -= other.decimalNo;
this->toBinary();
return *this;
}
// Overloading * operator for multiplication (Convert to base 10 multiply and convert back into base 2)
Binary operator*(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo * other.decimalNo;
result.toBinary();
return result;
}
// Overloading / operator for division (Convert to base 10 divide and convert back into base 2)
Binary operator/(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo / other.decimalNo;
result.toBinary();
return result;
}
// Overloading % operator for modulus (Convert to base 10 modulus and convert back into base 2)
Binary operator%(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo % other.decimalNo;
result.toBinary();
return result;
}
// Overloading | operator for or
Binary operator|(const Binary& other) const{
Binary result("", 2);
// if(this->binaryString.length() < other.binaryString.length()){
// for(int i=0;i<other.binaryString.length() - this->binaryString.length();i++) this->binaryString = '0' + this->binaryString;
// }
// else if(this->binaryString.length() > other.binaryString.length()){
// for(int i=0;i<this->binaryString.length() - other.binaryString.length();i++) other.binaryString = '0' + other.binaryString;
// }
// for(int i=0;i<this->binaryString.length();i++){
// result.binaryString += this->binaryString[i] || other.binaryString[i];
// }
result.decimalNo = this->decimalNo | other.decimalNo;
result.toBinary();
return result;
}
// Overloading ^ operator for xor
Binary operator^(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo ^ other.decimalNo;
result.toBinary();
return result;
}
// Overloading & operator for and
Binary operator&(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo & other.decimalNo;
result.toBinary();
return result;
}
// Overloading ! operator for 2's Compliment
Binary operator!() const{
}
// Overloading ~ operator for 1's Compliment
Binary operator~() const{
}
// Overloading left shift operator
Binary operator<<(int shiftAmount) const{
Binary result("", 2);
result.decimalNo = this->decimalNo << shiftAmount;
result.toBinary();
return result;
}
// Overloading right shift operator
Binary operator>>(int shiftAmount) const{
Binary result("", 2);
result.decimalNo = this->decimalNo >> shiftAmount;
result.toBinary();
return result;
}
// Overloading input operator
friend istream& operator>>(istream& input, Binary& other);
// Overloading output operator (Display Both Binary as well as Integer value)
friend ostream& operator<<(ostream& output, const Binary& other);
};
istream& operator>>(istream& input, Binary& other){
cout<<"Enter binary: ";
input>>other.binaryString;
cout<<"Enter base: ";
input>>other.base;
other.toBinary();
return input;
}
ostream& operator<<(ostream& output, const Binary& other){
cout<<"binary: ";
}

View file

@ -0,0 +1,152 @@
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
class Binary {
private:
string binaryString;
int base;
int decimalNo;
public:
// Constructor (If base is greater than 2 first convert into base 10 using that base and then convert back into binary and change the base to 2)
Binary(string binaryStr, int base = 2){
toDecimal();
}
void toBinary(){
binaryString = "";
int temp = decimalNo;
while(temp > 0){
binaryString = char(temp%2 + '0') + binaryString;
temp /= 2;
}
}
void toDecimal(){
decimalNo = 0;
for(int i=0;i<binaryString.length();i++) decimalNo += (binaryString[i] - '0')*pow(2, binaryString.length()-1-i);
}
// Overloading + operator for addition
Binary operator+(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo + other.decimalNo;
result.toBinary();
return result;
}
// Overloading - operator for subtraction
Binary operator-(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo - other.decimalNo;
result.toBinary();
return result;
}
// Overloading += operator for addition
Binary& operator+=(const Binary& other){
this->decimalNo += other.decimalNo;
this->toBinary();
return *this;
}
// Overloading -= operator for subtraction
Binary& operator-=(const Binary& other){
this->decimalNo -= other.decimalNo;
this->toBinary();
return *this;
}
// Overloading * operator for multiplication (Convert to base 10 multiply and convert back into base 2)
Binary operator*(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo * other.decimalNo;
result.toBinary();
return result;
}
// Overloading / operator for division (Convert to base 10 divide and convert back into base 2)
Binary operator/(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo / other.decimalNo;
result.toBinary();
return result;
}
// Overloading % operator for modulus (Convert to base 10 modulus and convert back into base 2)
Binary operator%(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo % other.decimalNo;
result.toBinary();
return result;
}
// Overloading | operator for or
Binary operator|(const Binary& other) const{
Binary result("", 2);
// if(this->binaryString.length() < other.binaryString.length()){
// for(int i=0;i<other.binaryString.length() - this->binaryString.length();i++) this->binaryString = '0' + this->binaryString;
// }
// else if(this->binaryString.length() > other.binaryString.length()){
// for(int i=0;i<this->binaryString.length() - other.binaryString.length();i++) other.binaryString = '0' + other.binaryString;
// }
// for(int i=0;i<this->binaryString.length();i++){
// result.binaryString += this->binaryString[i] || other.binaryString[i];
// }
result.decimalNo = this->decimalNo | other.decimalNo;
result.toBinary();
return result;
}
// Overloading ^ operator for xor
Binary operator^(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo ^ other.decimalNo;
result.toBinary();
return result;
}
// Overloading & operator for and
Binary operator&(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo & other.decimalNo;
result.toBinary();
return result;
}
// Overloading ! operator for 2's Compliment
Binary operator!() const{
}
// Overloading ~ operator for 1's Compliment
Binary operator~() const{
}
// Overloading left shift operator
Binary operator<<(int shiftAmount) const{
}
// Overloading right shift operator
Binary operator>>(int shiftAmount) const{
}
// Overloading input operator
friend istream& operator>>(istream& input, Binary& other){
}
// Overloading output operator (Display Both Binary as well as Integer value)
friend ostream& operator<<(ostream& output, const Binary& other){
}
};

View file

@ -0,0 +1,115 @@
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
class Binary {
private:
string binaryString;
int base;
int decimalNo;
public:
// Constructor (If base is greater than 2 first convert into base 10 using that base and then convert back into binary and change the base to 2)
Binary(string binaryStr, int base = 2){
if(base > 2){
}
}
void toBinary(){
binaryString = "";
int temp = decimalNo;
while(temp > 0){
binaryString = char(temp%2 + '0') + binaryString;
temp /= 2;
}
}
void toDecimal(){
decimalNo = 0;
for(int i=0;i<binaryString.length();i++) decimalNo += (binaryString[i] - '0')*pow(2, binaryString.length() -1 - i);
}
// Overloading + operator for addition
Binary operator+(const Binary& other) const{
}
// Overloading - operator for subtraction
Binary operator-(const Binary& other) const{
}
// Overloading += operator for addition
Binary& operator+=(const Binary& other) const{
}
// Overloading -= operator for subtraction
Binary& operator-=(const Binary& other) const{
}
// Overloading * operator for multiplication (Convert to base 10 multiply and convert back into base 2)
Binary operator*(const Binary& other) const{
}
// Overloading / operator for division (Convert to base 10 divide and convert back into base 2)
Binary operator/(const Binary& other) const{
}
// Overloading % operator for modulus (Convert to base 10 modulus and convert back into base 2)
Binary operator%(const Binary& other) const{
}
// Overloading | operator for or
Binary operator|(const Binary& other) const{
}
// Overloading ^ operator for xor
Binary operator^(const Binary& other) const{
}
// Overloading & operator for and
Binary operator&(const Binary& other) const{
}
// Overloading ! operator for 2's Compliment
Binary operator!() const{
}
// Overloading ~ operator for 1's Compliment
Binary operator~() const{
}
// Overloading left shift operator
Binary operator<<(int shiftAmount) const{
}
// Overloading right shift operator
Binary operator>>(int shiftAmount) const{
}
// Overloading input operator
friend istream& operator>>(istream& input, Binary& other){
}
// Overloading output operator (Display Both Binary as well as Integer value)
friend ostream& operator<<(ostream& output, const Binary& other){
}
};

View file

@ -0,0 +1,113 @@
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
class Binary {
private:
string binaryString;
int base;
int decimalNo;
public:
// Constructor (If base is greater than 2 first convert into base 10 using that base and then convert back into binary and change the base to 2)
Binary(string binaryStr, int base = 2){
toDecimal();
}
void toBinary(){
binaryString = "";
int temp = decimalNo;
while(temp > 0){
binaryString = char(temp%2 + '0') + binaryString;
temp /= 2;
}
}
void toDecimal(){
decimalNo = 0;
for(int i=0;i<binaryString.length();i++) decimalNo += (binaryString[i] - '0')*pow(2, binaryString.length()-1-i);
}
// Overloading + operator for addition
Binary operator+(const Binary& other) const{
}
// Overloading - operator for subtraction
Binary operator-(const Binary& other) const{
}
// Overloading += operator for addition
Binary& operator+=(const Binary& other) const{
}
// Overloading -= operator for subtraction
Binary& operator-=(const Binary& other) const{
}
// Overloading * operator for multiplication (Convert to base 10 multiply and convert back into base 2)
Binary operator*(const Binary& other) const{
}
// Overloading / operator for division (Convert to base 10 divide and convert back into base 2)
Binary operator/(const Binary& other) const{
}
// Overloading % operator for modulus (Convert to base 10 modulus and convert back into base 2)
Binary operator%(const Binary& other) const{
}
// Overloading | operator for or
Binary operator|(const Binary& other) const{
}
// Overloading ^ operator for xor
Binary operator^(const Binary& other) const{
}
// Overloading & operator for and
Binary operator&(const Binary& other) const{
}
// Overloading ! operator for 2's Compliment
Binary operator!() const{
}
// Overloading ~ operator for 1's Compliment
Binary operator~() const{
}
// Overloading left shift operator
Binary operator<<(int shiftAmount) const{
}
// Overloading right shift operator
Binary operator>>(int shiftAmount) const{
}
// Overloading input operator
friend istream& operator>>(istream& input, Binary& other){
}
// Overloading output operator (Display Both Binary as well as Integer value)
friend ostream& operator<<(ostream& output, const Binary& other){
}
};

View file

@ -0,0 +1,164 @@
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
class Binary {
private:
string binaryString;
int base;
int decimalNo;
public:
// Constructor (If base is greater than 2 first convert into base 10 using that base and then convert back into binary and change the base to 2)
Binary(string binaryStr, int base = 2){
toDecimal();
}
void toBinary(){
binaryString = "";
int temp = decimalNo;
while(temp > 0){
binaryString = char(temp%2 + '0') + binaryString;
temp /= 2;
}
}
void toDecimal(){
decimalNo = 0;
for(int i=0;i<binaryString.length();i++) decimalNo += (binaryString[i] - '0')*pow(2, binaryString.length()-1-i);
}
// Overloading + operator for addition
Binary operator+(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo + other.decimalNo;
result.toBinary();
return result;
}
// Overloading - operator for subtraction
Binary operator-(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo - other.decimalNo;
result.toBinary();
return result;
}
// Overloading += operator for addition
Binary& operator+=(const Binary& other){
this->decimalNo += other.decimalNo;
this->toBinary();
return *this;
}
// Overloading -= operator for subtraction
Binary& operator-=(const Binary& other){
this->decimalNo -= other.decimalNo;
this->toBinary();
return *this;
}
// Overloading * operator for multiplication (Convert to base 10 multiply and convert back into base 2)
Binary operator*(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo * other.decimalNo;
result.toBinary();
return result;
}
// Overloading / operator for division (Convert to base 10 divide and convert back into base 2)
Binary operator/(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo / other.decimalNo;
result.toBinary();
return result;
}
// Overloading % operator for modulus (Convert to base 10 modulus and convert back into base 2)
Binary operator%(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo % other.decimalNo;
result.toBinary();
return result;
}
// Overloading | operator for or
Binary operator|(const Binary& other) const{
Binary result("", 2);
// if(this->binaryString.length() < other.binaryString.length()){
// for(int i=0;i<other.binaryString.length() - this->binaryString.length();i++) this->binaryString = '0' + this->binaryString;
// }
// else if(this->binaryString.length() > other.binaryString.length()){
// for(int i=0;i<this->binaryString.length() - other.binaryString.length();i++) other.binaryString = '0' + other.binaryString;
// }
// for(int i=0;i<this->binaryString.length();i++){
// result.binaryString += this->binaryString[i] || other.binaryString[i];
// }
result.decimalNo = this->decimalNo | other.decimalNo;
result.toBinary();
return result;
}
// Overloading ^ operator for xor
Binary operator^(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo ^ other.decimalNo;
result.toBinary();
return result;
}
// Overloading & operator for and
Binary operator&(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo & other.decimalNo;
result.toBinary();
return result;
}
// Overloading ! operator for 2's Compliment
Binary operator!() const{
}
// Overloading ~ operator for 1's Compliment
Binary operator~() const{
}
// Overloading left shift operator
Binary operator<<(int shiftAmount) const{
Binary result("", 2);
result.decimalNo = this->decimalNo << shiftAmount;
result.toBinary();
return result;
}
// Overloading right shift operator
Binary operator>>(int shiftAmount) const{
Binary result("", 2);
result.decimalNo = this->decimalNo >> shiftAmount;
result.toBinary();
return result;
}
// Overloading input operator
friend istream& operator>>(istream& input, Binary& other);
// Overloading output operator (Display Both Binary as well as Integer value)
friend ostream& operator<<(ostream& output, const Binary& other);
};
istream& operator>>(istream& input, Binary& other){
cout<<"Enter binary: ";
input>>other.binaryString;
}
ostream& operator<<(ostream& output, const Binary& other){
}

View file

@ -0,0 +1,172 @@
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
class Binary {
private:
string binaryString;
int base;
int decimalNo;
public:
// Constructor (If base is greater than 2 first convert into base 10 using that base and then convert back into binary and change the base to 2)
Binary(string binaryStr, int base = 2){
toDecimal();
}
void toBinary(){
binaryString = "";
int temp = decimalNo;
while(temp > 0){
binaryString = char(temp%2 + '0') + binaryString;
temp /= 2;
}
}
void toDecimal(){
decimalNo = 0;
for(int i=0;i<binaryString.length();i++) decimalNo += (binaryString[i] - '0')*pow(2, binaryString.length()-1-i);
}
// Overloading + operator for addition
Binary operator+(const Binary& other) const{
Binary result("");
result.decimalNo = this->decimalNo + other.decimalNo;
result.toBinary();
return result;
}
// Overloading - operator for subtraction
Binary operator-(const Binary& other) const{
Binary result("");
result.decimalNo = this->decimalNo - other.decimalNo;
result.toBinary();
return result;
}
// Overloading += operator for addition
Binary& operator+=(const Binary& other){
this->decimalNo += other.decimalNo;
this->toBinary();
return *this;
}
// Overloading -= operator for subtraction
Binary& operator-=(const Binary& other){
this->decimalNo -= other.decimalNo;
this->toBinary();
return *this;
}
// Overloading * operator for multiplication (Convert to base 10 multiply and convert back into base 2)
Binary operator*(const Binary& other) const{
Binary result("");
result.decimalNo = this->decimalNo * other.decimalNo;
result.toBinary();
return result;
}
// Overloading / operator for division (Convert to base 10 divide and convert back into base 2)
Binary operator/(const Binary& other) const{
Binary result("");
result.decimalNo = this->decimalNo / other.decimalNo;
result.toBinary();
return result;
}
// Overloading % operator for modulus (Convert to base 10 modulus and convert back into base 2)
Binary operator%(const Binary& other) const{
Binary result("");
result.decimalNo = this->decimalNo % other.decimalNo;
result.toBinary();
return result;
}
// Overloading | operator for or
Binary operator|(const Binary& other) const{
Binary result("");
// if(this->binaryString.length() < other.binaryString.length()){
// for(int i=0;i<other.binaryString.length() - this->binaryString.length();i++) this->binaryString = '0' + this->binaryString;
// }
// else if(this->binaryString.length() > other.binaryString.length()){
// for(int i=0;i<this->binaryString.length() - other.binaryString.length();i++) other.binaryString = '0' + other.binaryString;
// }
// for(int i=0;i<this->binaryString.length();i++){
// result.binaryString += this->binaryString[i] || other.binaryString[i];
// }
result.decimalNo = this->decimalNo | other.decimalNo;
result.toBinary();
return result;
}
// Overloading ^ operator for xor
Binary operator^(const Binary& other) const{
Binary result("");
result.decimalNo = this->decimalNo ^ other.decimalNo;
result.toBinary();
return result;
}
// Overloading & operator for and
Binary operator&(const Binary& other) const{
Binary result("");
result.decimalNo = this->decimalNo & other.decimalNo;
result.toBinary();
return result;
}
// Overloading ! operator for 2's Compliment
Binary operator!() const{
}
// Overloading ~ operator for 1's Compliment
Binary operator~() const{
Binary result("")
}
// Overloading left shift operator
Binary operator<<(int shiftAmount) const{
Binary result("", 2);
result.decimalNo = this->decimalNo << shiftAmount;
result.toBinary();
return result;
}
// Overloading right shift operator
Binary operator>>(int shiftAmount) const{
Binary result("", 2);
result.decimalNo = this->decimalNo >> shiftAmount;
result.toBinary();
return result;
}
// Overloading input operator
friend istream& operator>>(istream& input, Binary& other);
// Overloading output operator (Display Both Binary as well as Integer value)
friend ostream& operator<<(ostream& output, const Binary& other);
};
istream& operator>>(istream& input, Binary& other){
cout<<"Enter binary: ";
input>>other.binaryString;
cout<<"Enter base: ";
input>>other.base;
other.toBinary();
return input;
}
ostream& operator<<(ostream& output, const Binary& other){
cout<<"Binary: ";
output<<other.binaryString<<endl;
cout<<"Decimal value: ";
output<<other.decimalNo<<endl;
cout<<"Base: ";
output<<other.base<<endl;
}

View file

@ -0,0 +1,142 @@
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
class Binary {
private:
string binaryString;
int base;
int decimalNo;
public:
// Constructor (If base is greater than 2 first convert into base 10 using that base and then convert back into binary and change the base to 2)
Binary(string binaryStr, int base = 2){
toDecimal();
}
void toBinary(){
binaryString = "";
int temp = decimalNo;
while(temp > 0){
binaryString = char(temp%2 + '0') + binaryString;
temp /= 2;
}
}
void toDecimal(){
decimalNo = 0;
for(int i=0;i<binaryString.length();i++) decimalNo += (binaryString[i] - '0')*pow(2, binaryString.length()-1-i);
}
// Overloading + operator for addition
Binary operator+(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo + other.decimalNo;
result.toBinary();
return result;
}
// Overloading - operator for subtraction
Binary operator-(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo - other.decimalNo;
result.toBinary();
return result;
}
// Overloading += operator for addition
Binary& operator+=(const Binary& other){
this->decimalNo += other.decimalNo;
this->toBinary();
return *this;
}
// Overloading -= operator for subtraction
Binary& operator-=(const Binary& other){
this->decimalNo -= other.decimalNo;
this->toBinary();
return *this;
}
// Overloading * operator for multiplication (Convert to base 10 multiply and convert back into base 2)
Binary operator*(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo * other.decimalNo;
result.toBinary();
return result;
}
// Overloading / operator for division (Convert to base 10 divide and convert back into base 2)
Binary operator/(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo / other.decimalNo;
result.toBinary();
return result;
}
// Overloading % operator for modulus (Convert to base 10 modulus and convert back into base 2)
Binary operator%(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo % other.decimalNo;
result.toBinary();
return result;
}
// Overloading | operator for or
Binary operator|(Binary& other){
Binary("", 2);
if(this->binaryString.length() < other.binaryString.length()){
for(int i=0;i<other.binaryString.length() - this->binaryString.length();i++){
this->binaryString = '0' + this->binaryString;
}
}
else if(this->binaryString.length() > other.binaryString.length()){
for(int i=0;i<this->binaryString.length() - other.binaryString.length();i++){
other.binaryString = '0' + other.binaryString;
}
}
}
// Overloading ^ operator for xor
Binary operator^(const Binary& other) const{
}
// Overloading & operator for and
Binary operator&(const Binary& other) const{
}
// Overloading ! operator for 2's Compliment
Binary operator!() const{
}
// Overloading ~ operator for 1's Compliment
Binary operator~() const{
}
// Overloading left shift operator
Binary operator<<(int shiftAmount) const{
}
// Overloading right shift operator
Binary operator>>(int shiftAmount) const{
}
// Overloading input operator
friend istream& operator>>(istream& input, Binary& other){
}
// Overloading output operator (Display Both Binary as well as Integer value)
friend ostream& operator<<(ostream& output, const Binary& other){
}
};

View file

@ -0,0 +1 @@
{"version":1,"resource":"file:///home/rafayahmad/Stuff/OOP%20Assignment%2004/Q2.cpp","entries":[{"id":"JlfZ.cpp","timestamp":1713273577642},{"id":"avdL.cpp","timestamp":1713273597152},{"id":"XB7y.cpp","timestamp":1713273608801},{"id":"pkgm.cpp","timestamp":1713273634538},{"id":"b2Af.cpp","timestamp":1713273664440},{"id":"NbDT.cpp","timestamp":1713273679180},{"id":"1BYE.cpp","timestamp":1713273767351},{"id":"xJe7.cpp","timestamp":1713273802127},{"id":"5gO0.cpp","timestamp":1713273819013},{"id":"gLdN.cpp","timestamp":1713273835593},{"id":"xyLq.cpp","timestamp":1713273856147},{"id":"Q0vt.cpp","timestamp":1713273873274},{"id":"xFP9.cpp","timestamp":1713273910421},{"id":"XNyE.cpp","timestamp":1713273929122},{"id":"jFzl.cpp","timestamp":1713274023829},{"id":"21tk.cpp","timestamp":1713274047792},{"id":"DK8B.cpp","timestamp":1713274155359},{"id":"0AHD.cpp","timestamp":1713274177564},{"id":"Rzv3.cpp","timestamp":1713274195735},{"id":"0PlU.cpp","timestamp":1713274258819},{"id":"cMB0.cpp","timestamp":1713274277134},{"id":"ZP9f.cpp","timestamp":1713274292538},{"id":"tlQa.cpp","timestamp":1713274324890},{"id":"PTuU.cpp","timestamp":1713274356668},{"id":"10pm.cpp","timestamp":1713274369411},{"id":"T8x1.cpp","timestamp":1713274388656},{"id":"9qgS.cpp","timestamp":1713274450181},{"id":"gFSR.cpp","timestamp":1713274519850},{"id":"wbAx.cpp","timestamp":1713274549367},{"id":"aoEF.cpp","timestamp":1713274575561},{"id":"4uEo.cpp","timestamp":1713274648943},{"id":"5Wej.cpp","timestamp":1713274661323},{"id":"nYHN.cpp","timestamp":1713274675920},{"id":"Tyn6.cpp","timestamp":1713274704798},{"id":"fbHV.cpp","timestamp":1713324427401},{"id":"bsMW.cpp","timestamp":1713324458886},{"id":"szWx.cpp","timestamp":1713324481969},{"id":"NGXH.cpp","timestamp":1713324526863},{"id":"ZTyJ.cpp","timestamp":1713324632638},{"id":"k4Kr.cpp","timestamp":1713324716270},{"id":"6Kb9.cpp","timestamp":1713325374999},{"id":"mGn6.cpp","timestamp":1713325484585},{"id":"c1DH.cpp","timestamp":1713325534028},{"id":"lX80.cpp","timestamp":1713325558314},{"id":"s5JJ.cpp","timestamp":1713325574141},{"id":"I0es.cpp","timestamp":1713325622934},{"id":"kdtH.cpp","timestamp":1713325677793},{"id":"8gsa.cpp","timestamp":1713325761633},{"id":"N5qt.cpp","timestamp":1713325789429},{"id":"o8zr.cpp","timestamp":1713451086105}]}

View file

@ -0,0 +1,162 @@
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
class Binary {
private:
string binaryString;
int base;
int decimalNo;
public:
// Constructor (If base is greater than 2 first convert into base 10 using that base and then convert back into binary and change the base to 2)
Binary(string binaryStr, int base = 2){
toDecimal();
}
void toBinary(){
binaryString = "";
int temp = decimalNo;
while(temp > 0){
binaryString = char(temp%2 + '0') + binaryString;
temp /= 2;
}
}
void toDecimal(){
decimalNo = 0;
for(int i=0;i<binaryString.length();i++) decimalNo += (binaryString[i] - '0')*pow(2, binaryString.length()-1-i);
}
// Overloading + operator for addition
Binary operator+(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo + other.decimalNo;
result.toBinary();
return result;
}
// Overloading - operator for subtraction
Binary operator-(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo - other.decimalNo;
result.toBinary();
return result;
}
// Overloading += operator for addition
Binary& operator+=(const Binary& other){
this->decimalNo += other.decimalNo;
this->toBinary();
return *this;
}
// Overloading -= operator for subtraction
Binary& operator-=(const Binary& other){
this->decimalNo -= other.decimalNo;
this->toBinary();
return *this;
}
// Overloading * operator for multiplication (Convert to base 10 multiply and convert back into base 2)
Binary operator*(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo * other.decimalNo;
result.toBinary();
return result;
}
// Overloading / operator for division (Convert to base 10 divide and convert back into base 2)
Binary operator/(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo / other.decimalNo;
result.toBinary();
return result;
}
// Overloading % operator for modulus (Convert to base 10 modulus and convert back into base 2)
Binary operator%(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo % other.decimalNo;
result.toBinary();
return result;
}
// Overloading | operator for or
Binary operator|(const Binary& other) const{
Binary result("", 2);
// if(this->binaryString.length() < other.binaryString.length()){
// for(int i=0;i<other.binaryString.length() - this->binaryString.length();i++) this->binaryString = '0' + this->binaryString;
// }
// else if(this->binaryString.length() > other.binaryString.length()){
// for(int i=0;i<this->binaryString.length() - other.binaryString.length();i++) other.binaryString = '0' + other.binaryString;
// }
// for(int i=0;i<this->binaryString.length();i++){
// result.binaryString += this->binaryString[i] || other.binaryString[i];
// }
result.decimalNo = this->decimalNo | other.decimalNo;
result.toBinary();
return result;
}
// Overloading ^ operator for xor
Binary operator^(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo ^ other.decimalNo;
result.toBinary();
return result;
}
// Overloading & operator for and
Binary operator&(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo & other.decimalNo;
result.toBinary();
return result;
}
// Overloading ! operator for 2's Compliment
Binary operator!() const{
}
// Overloading ~ operator for 1's Compliment
Binary operator~() const{
}
// Overloading left shift operator
Binary operator<<(int shiftAmount) const{
Binary result("", 2);
result.decimalNo = this->decimalNo << shiftAmount;
result.toBinary();
return result;
}
// Overloading right shift operator
Binary operator>>(int shiftAmount) const{
Binary result("", 2);
result.decimalNo = this->decimalNo >> shiftAmount;
result.toBinary();
return result;
}
// Overloading input operator
friend istream& operator>>(istream& input, Binary& other);
// Overloading output operator (Display Both Binary as well as Integer value)
friend ostream& operator<<(ostream& output, const Binary& other);
};
istream& operator>>(istream& input, Binary& other){
}
ostream& operator<<(ostream& output, const Binary& other){
}

View file

@ -0,0 +1,146 @@
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
class Binary {
private:
string binaryString;
int base;
int decimalNo;
public:
// Constructor (If base is greater than 2 first convert into base 10 using that base and then convert back into binary and change the base to 2)
Binary(string binaryStr, int base = 2){
toDecimal();
}
void toBinary(){
binaryString = "";
int temp = decimalNo;
while(temp > 0){
binaryString = char(temp%2 + '0') + binaryString;
temp /= 2;
}
}
void toDecimal(){
decimalNo = 0;
for(int i=0;i<binaryString.length();i++) decimalNo += (binaryString[i] - '0')*pow(2, binaryString.length()-1-i);
}
// Overloading + operator for addition
Binary operator+(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo + other.decimalNo;
result.toBinary();
return result;
}
// Overloading - operator for subtraction
Binary operator-(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo - other.decimalNo;
result.toBinary();
return result;
}
// Overloading += operator for addition
Binary& operator+=(const Binary& other){
this->decimalNo += other.decimalNo;
this->toBinary();
return *this;
}
// Overloading -= operator for subtraction
Binary& operator-=(const Binary& other){
this->decimalNo -= other.decimalNo;
this->toBinary();
return *this;
}
// Overloading * operator for multiplication (Convert to base 10 multiply and convert back into base 2)
Binary operator*(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo * other.decimalNo;
result.toBinary();
return result;
}
// Overloading / operator for division (Convert to base 10 divide and convert back into base 2)
Binary operator/(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo / other.decimalNo;
result.toBinary();
return result;
}
// Overloading % operator for modulus (Convert to base 10 modulus and convert back into base 2)
Binary operator%(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo % other.decimalNo;
result.toBinary();
return result;
}
// Overloading | operator for or
Binary operator|(const Binary& other) const{
Binary result("", 2);
// if(this->binaryString.length() < other.binaryString.length()){
// for(int i=0;i<other.binaryString.length() - this->binaryString.length();i++) this->binaryString = '0' + this->binaryString;
// }
// else if(this->binaryString.length() > other.binaryString.length()){
// for(int i=0;i<this->binaryString.length() - other.binaryString.length();i++) other.binaryString = '0' + other.binaryString;
// }
// for(int i=0;i<this->binaryString.length();i++){
// result.binaryString += this->binaryString[i] || other.binaryString[i];
// }
result.decimalNo = this->decimalNo | other.decimalNo;
result.toBinary();
return result;
}
// Overloading ^ operator for xor
Binary operator^(const Binary& other) const{
}
// Overloading & operator for and
Binary operator&(const Binary& other) const{
}
// Overloading ! operator for 2's Compliment
Binary operator!() const{
}
// Overloading ~ operator for 1's Compliment
Binary operator~() const{
}
// Overloading left shift operator
Binary operator<<(int shiftAmount) const{
}
// Overloading right shift operator
Binary operator>>(int shiftAmount) const{
}
// Overloading input operator
friend istream& operator>>(istream& input, Binary& other){
}
// Overloading output operator (Display Both Binary as well as Integer value)
friend ostream& operator<<(ostream& output, const Binary& other){
}
};

View file

@ -0,0 +1,123 @@
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
class Binary {
private:
string binaryString;
int base;
int decimalNo;
public:
// Constructor (If base is greater than 2 first convert into base 10 using that base and then convert back into binary and change the base to 2)
Binary(string binaryStr, int base = 2){
toDecimal();
}
void toBinary(){
binaryString = "";
int temp = decimalNo;
while(temp > 0){
binaryString = char(temp%2 + '0') + binaryString;
temp /= 2;
}
}
void toDecimal(){
decimalNo = 0;
for(int i=0;i<binaryString.length();i++) decimalNo += (binaryString[i] - '0')*pow(2, binaryString.length()-1-i);
}
// Overloading + operator for addition
Binary operator+(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo + other.decimalNo;
result.toBinary();
return result;
}
// Overloading - operator for subtraction
Binary operator-(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo - other.decimalNo;
result.toBinary();
return result;
}
// Overloading += operator for addition
Binary& operator+=(const Binary& other){
this->decimalNo += other.decimalNo;
this->toBinary();
return *this;
}
// Overloading -= operator for subtraction
Binary& operator-=(const Binary& other){
this->decimalNo -= other.decimalNo;
this->toBinary();
return *this;
}
// Overloading * operator for multiplication (Convert to base 10 multiply and convert back into base 2)
Binary operator*(const Binary& other) const{
}
// Overloading / operator for division (Convert to base 10 divide and convert back into base 2)
Binary operator/(const Binary& other) const{
}
// Overloading % operator for modulus (Convert to base 10 modulus and convert back into base 2)
Binary operator%(const Binary& other) const{
}
// Overloading | operator for or
Binary operator|(const Binary& other) const{
}
// Overloading ^ operator for xor
Binary operator^(const Binary& other) const{
}
// Overloading & operator for and
Binary operator&(const Binary& other) const{
}
// Overloading ! operator for 2's Compliment
Binary operator!() const{
}
// Overloading ~ operator for 1's Compliment
Binary operator~() const{
}
// Overloading left shift operator
Binary operator<<(int shiftAmount) const{
}
// Overloading right shift operator
Binary operator>>(int shiftAmount) const{
}
// Overloading input operator
friend istream& operator>>(istream& input, Binary& other){
}
// Overloading output operator (Display Both Binary as well as Integer value)
friend ostream& operator<<(ostream& output, const Binary& other){
}
};

View file

@ -0,0 +1,133 @@
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
class Binary {
private:
string binaryString;
int base;
int decimalNo;
public:
// Constructor (If base is greater than 2 first convert into base 10 using that base and then convert back into binary and change the base to 2)
Binary(string binaryStr, int base = 2){
toDecimal();
}
void toBinary(){
binaryString = "";
int temp = decimalNo;
while(temp > 0){
binaryString = char(temp%2 + '0') + binaryString;
temp /= 2;
}
}
void toDecimal(){
decimalNo = 0;
for(int i=0;i<binaryString.length();i++) decimalNo += (binaryString[i] - '0')*pow(2, binaryString.length()-1-i);
}
// Overloading + operator for addition
Binary operator+(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo + other.decimalNo;
result.toBinary();
return result;
}
// Overloading - operator for subtraction
Binary operator-(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo - other.decimalNo;
result.toBinary();
return result;
}
// Overloading += operator for addition
Binary& operator+=(const Binary& other){
this->decimalNo += other.decimalNo;
this->toBinary();
return *this;
}
// Overloading -= operator for subtraction
Binary& operator-=(const Binary& other){
this->decimalNo -= other.decimalNo;
this->toBinary();
return *this;
}
// Overloading * operator for multiplication (Convert to base 10 multiply and convert back into base 2)
Binary operator*(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo * other.decimalNo;
result.toBinary();
return result;
}
// Overloading / operator for division (Convert to base 10 divide and convert back into base 2)
Binary operator/(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo / other.decimalNo;
result.toBinary();
return result;
}
// Overloading % operator for modulus (Convert to base 10 modulus and convert back into base 2)
Binary operator%(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo % other.decimalNo;
result.toBinary();
return result;
}
// Overloading | operator for or
Binary operator|(const Binary& other) const{
Binary("", 2);
}
// Overloading ^ operator for xor
Binary operator^(const Binary& other) const{
}
// Overloading & operator for and
Binary operator&(const Binary& other) const{
}
// Overloading ! operator for 2's Compliment
Binary operator!() const{
}
// Overloading ~ operator for 1's Compliment
Binary operator~() const{
}
// Overloading left shift operator
Binary operator<<(int shiftAmount) const{
}
// Overloading right shift operator
Binary operator>>(int shiftAmount) const{
}
// Overloading input operator
friend istream& operator>>(istream& input, Binary& other){
}
// Overloading output operator (Display Both Binary as well as Integer value)
friend ostream& operator<<(ostream& output, const Binary& other){
}
};

View file

@ -0,0 +1,168 @@
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
class Binary {
private:
string binaryString;
int base;
int decimalNo;
public:
// Constructor (If base is greater than 2 first convert into base 10 using that base and then convert back into binary and change the base to 2)
Binary(string binaryStr, int base = 2){
toDecimal();
}
void toBinary(){
binaryString = "";
int temp = decimalNo;
while(temp > 0){
binaryString = char(temp%2 + '0') + binaryString;
temp /= 2;
}
}
void toDecimal(){
decimalNo = 0;
for(int i=0;i<binaryString.length();i++) decimalNo += (binaryString[i] - '0')*pow(2, binaryString.length()-1-i);
}
// Overloading + operator for addition
Binary operator+(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo + other.decimalNo;
result.toBinary();
return result;
}
// Overloading - operator for subtraction
Binary operator-(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo - other.decimalNo;
result.toBinary();
return result;
}
// Overloading += operator for addition
Binary& operator+=(const Binary& other){
this->decimalNo += other.decimalNo;
this->toBinary();
return *this;
}
// Overloading -= operator for subtraction
Binary& operator-=(const Binary& other){
this->decimalNo -= other.decimalNo;
this->toBinary();
return *this;
}
// Overloading * operator for multiplication (Convert to base 10 multiply and convert back into base 2)
Binary operator*(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo * other.decimalNo;
result.toBinary();
return result;
}
// Overloading / operator for division (Convert to base 10 divide and convert back into base 2)
Binary operator/(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo / other.decimalNo;
result.toBinary();
return result;
}
// Overloading % operator for modulus (Convert to base 10 modulus and convert back into base 2)
Binary operator%(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo % other.decimalNo;
result.toBinary();
return result;
}
// Overloading | operator for or
Binary operator|(const Binary& other) const{
Binary result("", 2);
// if(this->binaryString.length() < other.binaryString.length()){
// for(int i=0;i<other.binaryString.length() - this->binaryString.length();i++) this->binaryString = '0' + this->binaryString;
// }
// else if(this->binaryString.length() > other.binaryString.length()){
// for(int i=0;i<this->binaryString.length() - other.binaryString.length();i++) other.binaryString = '0' + other.binaryString;
// }
// for(int i=0;i<this->binaryString.length();i++){
// result.binaryString += this->binaryString[i] || other.binaryString[i];
// }
result.decimalNo = this->decimalNo | other.decimalNo;
result.toBinary();
return result;
}
// Overloading ^ operator for xor
Binary operator^(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo ^ other.decimalNo;
result.toBinary();
return result;
}
// Overloading & operator for and
Binary operator&(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo & other.decimalNo;
result.toBinary();
return result;
}
// Overloading ! operator for 2's Compliment
Binary operator!() const{
}
// Overloading ~ operator for 1's Compliment
Binary operator~() const{
}
// Overloading left shift operator
Binary operator<<(int shiftAmount) const{
Binary result("", 2);
result.decimalNo = this->decimalNo << shiftAmount;
result.toBinary();
return result;
}
// Overloading right shift operator
Binary operator>>(int shiftAmount) const{
Binary result("", 2);
result.decimalNo = this->decimalNo >> shiftAmount;
result.toBinary();
return result;
}
// Overloading input operator
friend istream& operator>>(istream& input, Binary& other);
// Overloading output operator (Display Both Binary as well as Integer value)
friend ostream& operator<<(ostream& output, const Binary& other);
};
istream& operator>>(istream& input, Binary& other){
cout<<"Enter binary: ";
input>>other.binaryString;
cout<<"Enter base: ";
input>>other.base;
other.toBinary();
return input;
}
ostream& operator<<(ostream& output, const Binary& other){
cout<<"binary: ";
}

View file

@ -0,0 +1,176 @@
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
class Binary {
private:
string binaryString;
int base;
int decimalNo;
public:
// Constructor (If base is greater than 2 first convert into base 10 using that base and then convert back into binary and change the base to 2)
Binary(string binaryStr, int base = 2){
toDecimal();
}
void toBinary(){
binaryString = "";
int temp = decimalNo;
while(temp > 0){
binaryString = char(temp%2 + '0') + binaryString;
temp /= 2;
}
}
void toDecimal(){
decimalNo = 0;
for(int i=0;i<binaryString.length();i++) decimalNo += (binaryString[i] - '0')*pow(2, binaryString.length()-1-i);
}
// Overloading + operator for addition
Binary operator+(const Binary& other) const{
Binary result("");
result.decimalNo = this->decimalNo + other.decimalNo;
result.toBinary();
return result;
}
// Overloading - operator for subtraction
Binary operator-(const Binary& other) const{
Binary result("");
result.decimalNo = this->decimalNo - other.decimalNo;
result.toBinary();
return result;
}
// Overloading += operator for addition
Binary& operator+=(const Binary& other){
this->decimalNo += other.decimalNo;
this->toBinary();
return *this;
}
// Overloading -= operator for subtraction
Binary& operator-=(const Binary& other){
this->decimalNo -= other.decimalNo;
this->toBinary();
return *this;
}
// Overloading * operator for multiplication (Convert to base 10 multiply and convert back into base 2)
Binary operator*(const Binary& other) const{
Binary result("");
result.decimalNo = this->decimalNo * other.decimalNo;
result.toBinary();
return result;
}
// Overloading / operator for division (Convert to base 10 divide and convert back into base 2)
Binary operator/(const Binary& other) const{
Binary result("");
result.decimalNo = this->decimalNo / other.decimalNo;
result.toBinary();
return result;
}
// Overloading % operator for modulus (Convert to base 10 modulus and convert back into base 2)
Binary operator%(const Binary& other) const{
Binary result("");
result.decimalNo = this->decimalNo % other.decimalNo;
result.toBinary();
return result;
}
// Overloading | operator for or
Binary operator|(const Binary& other) const{
Binary result("");
// if(this->binaryString.length() < other.binaryString.length()){
// for(int i=0;i<other.binaryString.length() - this->binaryString.length();i++) this->binaryString = '0' + this->binaryString;
// }
// else if(this->binaryString.length() > other.binaryString.length()){
// for(int i=0;i<this->binaryString.length() - other.binaryString.length();i++) other.binaryString = '0' + other.binaryString;
// }
// for(int i=0;i<this->binaryString.length();i++){
// result.binaryString += this->binaryString[i] || other.binaryString[i];
// }
result.decimalNo = this->decimalNo | other.decimalNo;
result.toBinary();
return result;
}
// Overloading ^ operator for xor
Binary operator^(const Binary& other) const{
Binary result("");
result.decimalNo = this->decimalNo ^ other.decimalNo;
result.toBinary();
return result;
}
// Overloading & operator for and
Binary operator&(const Binary& other) const{
Binary result("");
result.decimalNo = this->decimalNo & other.decimalNo;
result.toBinary();
return result;
}
// Overloading ! operator for 2's Compliment
Binary operator!() const{
}
// Overloading ~ operator for 1's Compliment
Binary operator~() const{
for(int i=0;i<this->binaryString.length();i++){
if(this->binaryString[i] == '0') this->binaryString[i] = '1';
else this->binaryString[i] = '0';
}
}
// Overloading left shift operator
Binary operator<<(int shiftAmount) const{
Binary result("");
result.decimalNo = this->decimalNo << shiftAmount;
result.toBinary();
return result;
}
// Overloading right shift operator
Binary operator>>(int shiftAmount) const{
Binary result("");
result.decimalNo = this->decimalNo >> shiftAmount;
result.toBinary();
return result;
}
// Overloading input operator
friend istream& operator>>(istream& input, Binary& other);
// Overloading output operator (Display Both Binary as well as Integer value)
friend ostream& operator<<(ostream& output, const Binary& other);
};
istream& operator>>(istream& input, Binary& other){
cout<<"Enter binary: ";
input>>other.binaryString;
cout<<"Enter base: ";
input>>other.base;
other.toBinary();
return input;
}
ostream& operator<<(ostream& output, const Binary& other){
cout<<"Binary: ";
output<<other.binaryString<<endl;
cout<<"Decimal value: ";
output<<other.decimalNo<<endl;
cout<<"Base: ";
output<<other.base<<endl;
}

View file

@ -0,0 +1,173 @@
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
class Binary {
private:
string binaryString;
int base;
int decimalNo;
public:
// Constructor (If base is greater than 2 first convert into base 10 using that base and then convert back into binary and change the base to 2)
Binary(string binaryStr, int base = 2){
toDecimal();
}
void toBinary(){
binaryString = "";
int temp = decimalNo;
while(temp > 0){
binaryString = char(temp%2 + '0') + binaryString;
temp /= 2;
}
}
void toDecimal(){
decimalNo = 0;
for(int i=0;i<binaryString.length();i++) decimalNo += (binaryString[i] - '0')*pow(2, binaryString.length()-1-i);
}
// Overloading + operator for addition
Binary operator+(const Binary& other) const{
Binary result("");
result.decimalNo = this->decimalNo + other.decimalNo;
result.toBinary();
return result;
}
// Overloading - operator for subtraction
Binary operator-(const Binary& other) const{
Binary result("");
result.decimalNo = this->decimalNo - other.decimalNo;
result.toBinary();
return result;
}
// Overloading += operator for addition
Binary& operator+=(const Binary& other){
this->decimalNo += other.decimalNo;
this->toBinary();
return *this;
}
// Overloading -= operator for subtraction
Binary& operator-=(const Binary& other){
this->decimalNo -= other.decimalNo;
this->toBinary();
return *this;
}
// Overloading * operator for multiplication (Convert to base 10 multiply and convert back into base 2)
Binary operator*(const Binary& other) const{
Binary result("");
result.decimalNo = this->decimalNo * other.decimalNo;
result.toBinary();
return result;
}
// Overloading / operator for division (Convert to base 10 divide and convert back into base 2)
Binary operator/(const Binary& other) const{
Binary result("");
result.decimalNo = this->decimalNo / other.decimalNo;
result.toBinary();
return result;
}
// Overloading % operator for modulus (Convert to base 10 modulus and convert back into base 2)
Binary operator%(const Binary& other) const{
Binary result("");
result.decimalNo = this->decimalNo % other.decimalNo;
result.toBinary();
return result;
}
// Overloading | operator for or
Binary operator|(const Binary& other) const{
Binary result("");
// if(this->binaryString.length() < other.binaryString.length()){
// for(int i=0;i<other.binaryString.length() - this->binaryString.length();i++) this->binaryString = '0' + this->binaryString;
// }
// else if(this->binaryString.length() > other.binaryString.length()){
// for(int i=0;i<this->binaryString.length() - other.binaryString.length();i++) other.binaryString = '0' + other.binaryString;
// }
// for(int i=0;i<this->binaryString.length();i++){
// result.binaryString += this->binaryString[i] || other.binaryString[i];
// }
result.decimalNo = this->decimalNo | other.decimalNo;
result.toBinary();
return result;
}
// Overloading ^ operator for xor
Binary operator^(const Binary& other) const{
Binary result("");
result.decimalNo = this->decimalNo ^ other.decimalNo;
result.toBinary();
return result;
}
// Overloading & operator for and
Binary operator&(const Binary& other) const{
Binary result("");
result.decimalNo = this->decimalNo & other.decimalNo;
result.toBinary();
return result;
}
// Overloading ! operator for 2's Compliment
Binary operator!() const{
}
// Overloading ~ operator for 1's Compliment
Binary operator~() const{
Binary result("");
}
// Overloading left shift operator
Binary operator<<(int shiftAmount) const{
Binary result("");
result.decimalNo = this->decimalNo << shiftAmount;
result.toBinary();
return result;
}
// Overloading right shift operator
Binary operator>>(int shiftAmount) const{
Binary result("");
result.decimalNo = this->decimalNo >> shiftAmount;
result.toBinary();
return result;
}
// Overloading input operator
friend istream& operator>>(istream& input, Binary& other);
// Overloading output operator (Display Both Binary as well as Integer value)
friend ostream& operator<<(ostream& output, const Binary& other);
};
istream& operator>>(istream& input, Binary& other){
cout<<"Enter binary: ";
input>>other.binaryString;
cout<<"Enter base: ";
input>>other.base;
other.toBinary();
return input;
}
ostream& operator<<(ostream& output, const Binary& other){
cout<<"Binary: ";
output<<other.binaryString<<endl;
cout<<"Decimal value: ";
output<<other.decimalNo<<endl;
cout<<"Base: ";
output<<other.base<<endl;
}

View file

@ -0,0 +1,172 @@
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
class Binary {
private:
string binaryString;
int base;
int decimalNo;
public:
// Constructor (If base is greater than 2 first convert into base 10 using that base and then convert back into binary and change the base to 2)
Binary(string binaryStr, int base = 2){
toDecimal();
}
void toBinary(){
binaryString = "";
int temp = decimalNo;
while(temp > 0){
binaryString = char(temp%2 + '0') + binaryString;
temp /= 2;
}
}
void toDecimal(){
decimalNo = 0;
for(int i=0;i<binaryString.length();i++) decimalNo += (binaryString[i] - '0')*pow(2, binaryString.length()-1-i);
}
// Overloading + operator for addition
Binary operator+(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo + other.decimalNo;
result.toBinary();
return result;
}
// Overloading - operator for subtraction
Binary operator-(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo - other.decimalNo;
result.toBinary();
return result;
}
// Overloading += operator for addition
Binary& operator+=(const Binary& other){
this->decimalNo += other.decimalNo;
this->toBinary();
return *this;
}
// Overloading -= operator for subtraction
Binary& operator-=(const Binary& other){
this->decimalNo -= other.decimalNo;
this->toBinary();
return *this;
}
// Overloading * operator for multiplication (Convert to base 10 multiply and convert back into base 2)
Binary operator*(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo * other.decimalNo;
result.toBinary();
return result;
}
// Overloading / operator for division (Convert to base 10 divide and convert back into base 2)
Binary operator/(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo / other.decimalNo;
result.toBinary();
return result;
}
// Overloading % operator for modulus (Convert to base 10 modulus and convert back into base 2)
Binary operator%(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo % other.decimalNo;
result.toBinary();
return result;
}
// Overloading | operator for or
Binary operator|(const Binary& other) const{
Binary result("", 2);
// if(this->binaryString.length() < other.binaryString.length()){
// for(int i=0;i<other.binaryString.length() - this->binaryString.length();i++) this->binaryString = '0' + this->binaryString;
// }
// else if(this->binaryString.length() > other.binaryString.length()){
// for(int i=0;i<this->binaryString.length() - other.binaryString.length();i++) other.binaryString = '0' + other.binaryString;
// }
// for(int i=0;i<this->binaryString.length();i++){
// result.binaryString += this->binaryString[i] || other.binaryString[i];
// }
result.decimalNo = this->decimalNo | other.decimalNo;
result.toBinary();
return result;
}
// Overloading ^ operator for xor
Binary operator^(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo ^ other.decimalNo;
result.toBinary();
return result;
}
// Overloading & operator for and
Binary operator&(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo & other.decimalNo;
result.toBinary();
return result;
}
// Overloading ! operator for 2's Compliment
Binary operator!() const{
}
// Overloading ~ operator for 1's Compliment
Binary operator~() const{
}
// Overloading left shift operator
Binary operator<<(int shiftAmount) const{
Binary result("", 2);
result.decimalNo = this->decimalNo << shiftAmount;
result.toBinary();
return result;
}
// Overloading right shift operator
Binary operator>>(int shiftAmount) const{
Binary result("", 2);
result.decimalNo = this->decimalNo >> shiftAmount;
result.toBinary();
return result;
}
// Overloading input operator
friend istream& operator>>(istream& input, Binary& other);
// Overloading output operator (Display Both Binary as well as Integer value)
friend ostream& operator<<(ostream& output, const Binary& other);
};
istream& operator>>(istream& input, Binary& other){
cout<<"Enter binary: ";
input>>other.binaryString;
cout<<"Enter base: ";
input>>other.base;
other.toBinary();
return input;
}
ostream& operator<<(ostream& output, const Binary& other){
cout<<"Binary: ";
output<<other.binaryString<<endl;
cout<<"Decimal value: ";
output<<other.decimalNo<<endl;
cout<<"Base: ";
output<<other.base<<endl;
}

View file

@ -0,0 +1,155 @@
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
class Binary {
private:
string binaryString;
int base;
int decimalNo;
public:
// Constructor (If base is greater than 2 first convert into base 10 using that base and then convert back into binary and change the base to 2)
Binary(string binaryStr, int base = 2){
toDecimal();
}
void toBinary(){
binaryString = "";
int temp = decimalNo;
while(temp > 0){
binaryString = char(temp%2 + '0') + binaryString;
temp /= 2;
}
}
void toDecimal(){
decimalNo = 0;
for(int i=0;i<binaryString.length();i++) decimalNo += (binaryString[i] - '0')*pow(2, binaryString.length()-1-i);
}
// Overloading + operator for addition
Binary operator+(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo + other.decimalNo;
result.toBinary();
return result;
}
// Overloading - operator for subtraction
Binary operator-(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo - other.decimalNo;
result.toBinary();
return result;
}
// Overloading += operator for addition
Binary& operator+=(const Binary& other){
this->decimalNo += other.decimalNo;
this->toBinary();
return *this;
}
// Overloading -= operator for subtraction
Binary& operator-=(const Binary& other){
this->decimalNo -= other.decimalNo;
this->toBinary();
return *this;
}
// Overloading * operator for multiplication (Convert to base 10 multiply and convert back into base 2)
Binary operator*(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo * other.decimalNo;
result.toBinary();
return result;
}
// Overloading / operator for division (Convert to base 10 divide and convert back into base 2)
Binary operator/(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo / other.decimalNo;
result.toBinary();
return result;
}
// Overloading % operator for modulus (Convert to base 10 modulus and convert back into base 2)
Binary operator%(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo % other.decimalNo;
result.toBinary();
return result;
}
// Overloading | operator for or
Binary operator|(const Binary& other) const{
Binary result("", 2);
// if(this->binaryString.length() < other.binaryString.length()){
// for(int i=0;i<other.binaryString.length() - this->binaryString.length();i++) this->binaryString = '0' + this->binaryString;
// }
// else if(this->binaryString.length() > other.binaryString.length()){
// for(int i=0;i<this->binaryString.length() - other.binaryString.length();i++) other.binaryString = '0' + other.binaryString;
// }
// for(int i=0;i<this->binaryString.length();i++){
// result.binaryString += this->binaryString[i] || other.binaryString[i];
// }
result.decimalNo = this->decimalNo | other.decimalNo;
result.toBinary();
return result;
}
// Overloading ^ operator for xor
Binary operator^(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo ^ other.decimalNo;
result.toBinary();
return result;
}
// Overloading & operator for and
Binary operator&(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo & other.decimalNo;
result.toBinary();
return result;
}
// Overloading ! operator for 2's Compliment
Binary operator!() const{
}
// Overloading ~ operator for 1's Compliment
Binary operator~() const{
}
// Overloading left shift operator
Binary operator<<(int shiftAmount) const{
Binary result("", 2);
result.decimalNo = this->decimalNo << shiftAmount;
result.toBinary();
return result;
}
// Overloading right shift operator
Binary operator>>(int shiftAmount) const{
Binary result("", 2);
result.decimalNo = this->decimalNo >> shiftAmount;
result.toBinary();
return result;
}
// Overloading input operator
friend istream& operator>>(istream& input, Binary& other);
// Overloading output operator (Display Both Binary as well as Integer value)
friend ostream& operator<<(ostream& output, const Binary& other);
};

View file

@ -0,0 +1,167 @@
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
class Binary {
private:
string binaryString;
int base;
int decimalNo;
public:
// Constructor (If base is greater than 2 first convert into base 10 using that base and then convert back into binary and change the base to 2)
Binary(string binaryStr, int base = 2){
toDecimal();
}
void toBinary(){
binaryString = "";
int temp = decimalNo;
while(temp > 0){
binaryString = char(temp%2 + '0') + binaryString;
temp /= 2;
}
}
void toDecimal(){
decimalNo = 0;
for(int i=0;i<binaryString.length();i++) decimalNo += (binaryString[i] - '0')*pow(2, binaryString.length()-1-i);
}
// Overloading + operator for addition
Binary operator+(const Binary& other) const{
Binary result("");
result.decimalNo = this->decimalNo + other.decimalNo;
result.toBinary();
return result;
}
// Overloading - operator for subtraction
Binary operator-(const Binary& other) const{
Binary result("");
result.decimalNo = this->decimalNo - other.decimalNo;
result.toBinary();
return result;
}
// Overloading += operator for addition
Binary& operator+=(const Binary& other){
this->decimalNo += other.decimalNo;
this->toBinary();
return *this;
}
// Overloading -= operator for subtraction
Binary& operator-=(const Binary& other){
this->decimalNo -= other.decimalNo;
this->toBinary();
return *this;
}
// Overloading * operator for multiplication (Convert to base 10 multiply and convert back into base 2)
Binary operator*(const Binary& other) const{
Binary result("");
result.decimalNo = this->decimalNo * other.decimalNo;
result.toBinary();
return result;
}
// Overloading / operator for division (Convert to base 10 divide and convert back into base 2)
Binary operator/(const Binary& other) const{
Binary result("");
result.decimalNo = this->decimalNo / other.decimalNo;
result.toBinary();
return result;
}
// Overloading % operator for modulus (Convert to base 10 modulus and convert back into base 2)
Binary operator%(const Binary& other) const{
Binary result("");
result.decimalNo = this->decimalNo % other.decimalNo;
result.toBinary();
return result;
}
// Overloading | operator for or
Binary operator|(const Binary& other) const{
Binary result("");
result.decimalNo = this->decimalNo | other.decimalNo;
result.toBinary();
return result;
}
// Overloading ^ operator for xor
Binary operator^(const Binary& other) const{
Binary result("");
result.decimalNo = this->decimalNo ^ other.decimalNo;
result.toBinary();
return result;
}
// Overloading & operator for and
Binary operator&(const Binary& other) const{
Binary result("");
result.decimalNo = this->decimalNo & other.decimalNo;
result.toBinary();
return result;
}
// Overloading ! operator for 2's Compliment
Binary operator!() const{
Binary result("");
result.decimalNo = ~this->decimalNo + 1; // 2's complement is 1's complement + 1
result.toBinary();
return result;
}
// Overloading ~ operator for 1's Compliment
Binary operator~() const{
Binary result("");
result.decimalNo = ~this->decimalNo;
result.toBinary();
return result;
}
// Overloading left shift operator
Binary operator<<(int shiftAmount) const{
Binary result("");
result.decimalNo = this->decimalNo << shiftAmount;
result.toBinary();
return result;
}
// Overloading right shift operator
Binary operator>>(int shiftAmount) const{
Binary result("");
result.decimalNo = this->decimalNo >> shiftAmount;
result.toBinary();
return result;
}
// Overloading input operator
friend istream& operator>>(istream& input, Binary& other);
// Overloading output operator (Display Both Binary as well as Integer value)
friend ostream& operator<<(ostream& output, const Binary& other);
};
istream& operator>>(istream& input, Binary& other){
cout<<"Enter binary: ";
input>>other.binaryString;
cout<<"Enter base: ";
input>>other.base;
other.toBinary();
return input;
}
ostream& operator<<(ostream& output, const Binary& other){
cout<<"Binary: ";
output<<other.binaryString<<endl;
cout<<"Decimal value: ";
output<<other.decimalNo<<endl;
cout<<"Base: ";
output<<other.base<<endl;
}

View file

@ -0,0 +1,113 @@
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
class Binary {
private:
string binaryString;
int base;
int decimalNo;
public:
// Constructor (If base is greater than 2 first convert into base 10 using that base and then convert back into binary and change the base to 2)
Binary(string binaryStr, int base = 2){
toDecimal();
}
void toBinary(){
binaryString = "";
int temp = decimalNo;
while(temp > 0){
binaryString = char(temp%2 + '0') + binaryString;
temp /= 2;
}
}
void toDecimal(){
decimalNo = 0;
for(int i=0;i<binaryString.length();i++) decimalNo += (binaryString[i] - '0')*pow(2, binaryString.length()-1-i);
}
// Overloading + operator for addition
Binary operator+(const Binary& other) const{
}
// Overloading - operator for subtraction
Binary operator-(const Binary& other) const{
}
// Overloading += operator for addition
Binary& operator+=(const Binary& other) const{
}
// Overloading -= operator for subtraction
Binary& operator-=(const Binary& other) const{
}
// Overloading * operator for multiplication (Convert to base 10 multiply and convert back into base 2)
Binary operator*(const Binary& other) const{
}
// Overloading / operator for division (Convert to base 10 divide and convert back into base 2)
Binary operator/(const Binary& other) const{
}
// Overloading % operator for modulus (Convert to base 10 modulus and convert back into base 2)
Binary operator%(const Binary& other) const{
}
// Overloading | operator for or
Binary operator|(const Binary& other) const{
}
// Overloading ^ operator for xor
Binary operator^(const Binary& other) const{
}
// Overloading & operator for and
Binary operator&(const Binary& other) const{
}
// Overloading ! operator for 2's Compliment
Binary operator!() const{
}
// Overloading ~ operator for 1's Compliment
Binary operator~() const{
}
// Overloading left shift operator
Binary operator<<(int shiftAmount) const{
}
// Overloading right shift operator
Binary operator>>(int shiftAmount) const{
}
// Overloading input operator
friend istream& operator>>(istream& input, Binary& other){
}
// Overloading output operator (Display Both Binary as well as Integer value)
friend ostream& operator<<(ostream& output, const Binary& other){
}
};

View file

@ -0,0 +1,173 @@
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
class Binary {
private:
string binaryString;
int base;
int decimalNo;
public:
// Constructor (If base is greater than 2 first convert into base 10 using that base and then convert back into binary and change the base to 2)
Binary(string binaryStr, int base = 2){
toDecimal();
}
void toBinary(){
binaryString = "";
int temp = decimalNo;
while(temp > 0){
binaryString = char(temp%2 + '0') + binaryString;
temp /= 2;
}
}
void toDecimal(){
decimalNo = 0;
for(int i=0;i<binaryString.length();i++) decimalNo += (binaryString[i] - '0')*pow(2, binaryString.length()-1-i);
}
// Overloading + operator for addition
Binary operator+(const Binary& other) const{
Binary result("");
result.decimalNo = this->decimalNo + other.decimalNo;
result.toBinary();
return result;
}
// Overloading - operator for subtraction
Binary operator-(const Binary& other) const{
Binary result("");
result.decimalNo = this->decimalNo - other.decimalNo;
result.toBinary();
return result;
}
// Overloading += operator for addition
Binary& operator+=(const Binary& other){
this->decimalNo += other.decimalNo;
this->toBinary();
return *this;
}
// Overloading -= operator for subtraction
Binary& operator-=(const Binary& other){
this->decimalNo -= other.decimalNo;
this->toBinary();
return *this;
}
// Overloading * operator for multiplication (Convert to base 10 multiply and convert back into base 2)
Binary operator*(const Binary& other) const{
Binary result("");
result.decimalNo = this->decimalNo * other.decimalNo;
result.toBinary();
return result;
}
// Overloading / operator for division (Convert to base 10 divide and convert back into base 2)
Binary operator/(const Binary& other) const{
Binary result("");
result.decimalNo = this->decimalNo / other.decimalNo;
result.toBinary();
return result;
}
// Overloading % operator for modulus (Convert to base 10 modulus and convert back into base 2)
Binary operator%(const Binary& other) const{
Binary result("");
result.decimalNo = this->decimalNo % other.decimalNo;
result.toBinary();
return result;
}
// Overloading | operator for or
Binary operator|(const Binary& other) const{
Binary result("");
// if(this->binaryString.length() < other.binaryString.length()){
// for(int i=0;i<other.binaryString.length() - this->binaryString.length();i++) this->binaryString = '0' + this->binaryString;
// }
// else if(this->binaryString.length() > other.binaryString.length()){
// for(int i=0;i<this->binaryString.length() - other.binaryString.length();i++) other.binaryString = '0' + other.binaryString;
// }
// for(int i=0;i<this->binaryString.length();i++){
// result.binaryString += this->binaryString[i] || other.binaryString[i];
// }
result.decimalNo = this->decimalNo | other.decimalNo;
result.toBinary();
return result;
}
// Overloading ^ operator for xor
Binary operator^(const Binary& other) const{
Binary result("");
result.decimalNo = this->decimalNo ^ other.decimalNo;
result.toBinary();
return result;
}
// Overloading & operator for and
Binary operator&(const Binary& other) const{
Binary result("");
result.decimalNo = this->decimalNo & other.decimalNo;
result.toBinary();
return result;
}
// Overloading ! operator for 2's Compliment
Binary operator!() const{
}
// Overloading ~ operator for 1's Compliment
Binary operator~() const{
}
// Overloading left shift operator
Binary operator<<(int shiftAmount) const{
Binary result("");
result.decimalNo = this->decimalNo << shiftAmount;
result.toBinary();
return result;
}
// Overloading right shift operator
Binary operator>>(int shiftAmount) const{
Binary result("");
result.decimalNo = this->decimalNo >> shiftAmount;
result.toBinary();
return result;
}
// Overloading input operator
friend istream& operator>>(istream& input, Binary& other);
// Overloading output operator (Display Both Binary as well as Integer value)
friend ostream& operator<<(ostream& output, const Binary& other);
};
istream& operator>>(istream& input, Binary& other){
cout<<"Enter binary: ";
input>>other.binaryString;
cout<<"Enter base: ";
input>>other.base;
other.toBinary();
return input;
}
ostream& operator<<(ostream& output, const Binary& other){
cout<<"Binary: ";
output<<other.binaryString<<endl;
cout<<"Decimal value: ";
output<<other.decimalNo<<endl;
cout<<"Base: ";
output<<other.base<<endl;
}

View file

@ -0,0 +1,167 @@
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
class Binary {
private:
string binaryString;
int base;
int decimalNo;
public:
// Constructor (If base is greater than 2 first convert into base 10 using that base and then convert back into binary and change the base to 2)
Binary(string binaryStr, int base = 2){
toDecimal();
}
void toBinary(){
binaryString = "";
int temp = decimalNo;
while(temp > 0){
binaryString = char(temp%2 + '0') + binaryString;
temp /= 2;
}
}
void toDecimal(){
decimalNo = 0;
for(int i=0;i<binaryString.length();i++) decimalNo += (binaryString[i] - '0')*pow(2, binaryString.length()-1-i);
}
// Overloading + operator for addition
Binary operator+(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo + other.decimalNo;
result.toBinary();
return result;
}
// Overloading - operator for subtraction
Binary operator-(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo - other.decimalNo;
result.toBinary();
return result;
}
// Overloading += operator for addition
Binary& operator+=(const Binary& other){
this->decimalNo += other.decimalNo;
this->toBinary();
return *this;
}
// Overloading -= operator for subtraction
Binary& operator-=(const Binary& other){
this->decimalNo -= other.decimalNo;
this->toBinary();
return *this;
}
// Overloading * operator for multiplication (Convert to base 10 multiply and convert back into base 2)
Binary operator*(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo * other.decimalNo;
result.toBinary();
return result;
}
// Overloading / operator for division (Convert to base 10 divide and convert back into base 2)
Binary operator/(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo / other.decimalNo;
result.toBinary();
return result;
}
// Overloading % operator for modulus (Convert to base 10 modulus and convert back into base 2)
Binary operator%(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo % other.decimalNo;
result.toBinary();
return result;
}
// Overloading | operator for or
Binary operator|(const Binary& other) const{
Binary result("", 2);
// if(this->binaryString.length() < other.binaryString.length()){
// for(int i=0;i<other.binaryString.length() - this->binaryString.length();i++) this->binaryString = '0' + this->binaryString;
// }
// else if(this->binaryString.length() > other.binaryString.length()){
// for(int i=0;i<this->binaryString.length() - other.binaryString.length();i++) other.binaryString = '0' + other.binaryString;
// }
// for(int i=0;i<this->binaryString.length();i++){
// result.binaryString += this->binaryString[i] || other.binaryString[i];
// }
result.decimalNo = this->decimalNo | other.decimalNo;
result.toBinary();
return result;
}
// Overloading ^ operator for xor
Binary operator^(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo ^ other.decimalNo;
result.toBinary();
return result;
}
// Overloading & operator for and
Binary operator&(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo & other.decimalNo;
result.toBinary();
return result;
}
// Overloading ! operator for 2's Compliment
Binary operator!() const{
}
// Overloading ~ operator for 1's Compliment
Binary operator~() const{
}
// Overloading left shift operator
Binary operator<<(int shiftAmount) const{
Binary result("", 2);
result.decimalNo = this->decimalNo << shiftAmount;
result.toBinary();
return result;
}
// Overloading right shift operator
Binary operator>>(int shiftAmount) const{
Binary result("", 2);
result.decimalNo = this->decimalNo >> shiftAmount;
result.toBinary();
return result;
}
// Overloading input operator
friend istream& operator>>(istream& input, Binary& other);
// Overloading output operator (Display Both Binary as well as Integer value)
friend ostream& operator<<(ostream& output, const Binary& other);
};
istream& operator>>(istream& input, Binary& other){
cout<<"Enter binary: ";
input>>other.binaryString;
cout<<"Enter base: ";
input>>other.base;
other.toBinary();
}
ostream& operator<<(ostream& output, const Binary& other){
}

View file

@ -0,0 +1,142 @@
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
class Binary {
private:
string binaryString;
int base;
int decimalNo;
public:
// Constructor (If base is greater than 2 first convert into base 10 using that base and then convert back into binary and change the base to 2)
Binary(string binaryStr, int base = 2){
toDecimal();
}
void toBinary(){
binaryString = "";
int temp = decimalNo;
while(temp > 0){
binaryString = char(temp%2 + '0') + binaryString;
temp /= 2;
}
}
void toDecimal(){
decimalNo = 0;
for(int i=0;i<binaryString.length();i++) decimalNo += (binaryString[i] - '0')*pow(2, binaryString.length()-1-i);
}
// Overloading + operator for addition
Binary operator+(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo + other.decimalNo;
result.toBinary();
return result;
}
// Overloading - operator for subtraction
Binary operator-(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo - other.decimalNo;
result.toBinary();
return result;
}
// Overloading += operator for addition
Binary& operator+=(const Binary& other){
this->decimalNo += other.decimalNo;
this->toBinary();
return *this;
}
// Overloading -= operator for subtraction
Binary& operator-=(const Binary& other){
this->decimalNo -= other.decimalNo;
this->toBinary();
return *this;
}
// Overloading * operator for multiplication (Convert to base 10 multiply and convert back into base 2)
Binary operator*(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo * other.decimalNo;
result.toBinary();
return result;
}
// Overloading / operator for division (Convert to base 10 divide and convert back into base 2)
Binary operator/(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo / other.decimalNo;
result.toBinary();
return result;
}
// Overloading % operator for modulus (Convert to base 10 modulus and convert back into base 2)
Binary operator%(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo % other.decimalNo;
result.toBinary();
return result;
}
// Overloading | operator for or
Binary operator|(Binary& other){
Binary result("", 2);
if(this->binaryString.length() < other.binaryString.length()){
for(int i=0;i<other.binaryString.length() - this->binaryString.length();i++) this->binaryString = '0' + this->binaryString;
}
else if(this->binaryString.length() > other.binaryString.length()){
for(int i=0;i<this->binaryString.length() - other.binaryString.length();i++) other.binaryString = '0' + other.binaryString;
}
for(int i=0;i<this->binaryString.length();i++){
}
}
// Overloading ^ operator for xor
Binary operator^(const Binary& other) const{
}
// Overloading & operator for and
Binary operator&(const Binary& other) const{
}
// Overloading ! operator for 2's Compliment
Binary operator!() const{
}
// Overloading ~ operator for 1's Compliment
Binary operator~() const{
}
// Overloading left shift operator
Binary operator<<(int shiftAmount) const{
}
// Overloading right shift operator
Binary operator>>(int shiftAmount) const{
}
// Overloading input operator
friend istream& operator>>(istream& input, Binary& other){
}
// Overloading output operator (Display Both Binary as well as Integer value)
friend ostream& operator<<(ostream& output, const Binary& other){
}
};

View file

@ -0,0 +1,149 @@
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
class Binary {
private:
string binaryString;
int base;
int decimalNo;
public:
// Constructor (If base is greater than 2 first convert into base 10 using that base and then convert back into binary and change the base to 2)
Binary(string binaryStr, int base = 2){
toDecimal();
}
void toBinary(){
binaryString = "";
int temp = decimalNo;
while(temp > 0){
binaryString = char(temp%2 + '0') + binaryString;
temp /= 2;
}
}
void toDecimal(){
decimalNo = 0;
for(int i=0;i<binaryString.length();i++) decimalNo += (binaryString[i] - '0')*pow(2, binaryString.length()-1-i);
}
// Overloading + operator for addition
Binary operator+(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo + other.decimalNo;
result.toBinary();
return result;
}
// Overloading - operator for subtraction
Binary operator-(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo - other.decimalNo;
result.toBinary();
return result;
}
// Overloading += operator for addition
Binary& operator+=(const Binary& other){
this->decimalNo += other.decimalNo;
this->toBinary();
return *this;
}
// Overloading -= operator for subtraction
Binary& operator-=(const Binary& other){
this->decimalNo -= other.decimalNo;
this->toBinary();
return *this;
}
// Overloading * operator for multiplication (Convert to base 10 multiply and convert back into base 2)
Binary operator*(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo * other.decimalNo;
result.toBinary();
return result;
}
// Overloading / operator for division (Convert to base 10 divide and convert back into base 2)
Binary operator/(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo / other.decimalNo;
result.toBinary();
return result;
}
// Overloading % operator for modulus (Convert to base 10 modulus and convert back into base 2)
Binary operator%(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo % other.decimalNo;
result.toBinary();
return result;
}
// Overloading | operator for or
Binary operator|(const Binary& other) const{
Binary result("", 2);
// if(this->binaryString.length() < other.binaryString.length()){
// for(int i=0;i<other.binaryString.length() - this->binaryString.length();i++) this->binaryString = '0' + this->binaryString;
// }
// else if(this->binaryString.length() > other.binaryString.length()){
// for(int i=0;i<this->binaryString.length() - other.binaryString.length();i++) other.binaryString = '0' + other.binaryString;
// }
// for(int i=0;i<this->binaryString.length();i++){
// result.binaryString += this->binaryString[i] || other.binaryString[i];
// }
result.decimalNo = this->decimalNo | other.decimalNo;
result.toBinary();
return result;
}
// Overloading ^ operator for xor
Binary operator^(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo ^ other.decimalNo;
result.toBinary();
return result;
}
// Overloading & operator for and
Binary operator&(const Binary& other) const{
}
// Overloading ! operator for 2's Compliment
Binary operator!() const{
}
// Overloading ~ operator for 1's Compliment
Binary operator~() const{
}
// Overloading left shift operator
Binary operator<<(int shiftAmount) const{
}
// Overloading right shift operator
Binary operator>>(int shiftAmount) const{
}
// Overloading input operator
friend istream& operator>>(istream& input, Binary& other){
}
// Overloading output operator (Display Both Binary as well as Integer value)
friend ostream& operator<<(ostream& output, const Binary& other){
}
};

View file

@ -0,0 +1,132 @@
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
class Binary {
private:
string binaryString;
int base;
int decimalNo;
public:
// Constructor (If base is greater than 2 first convert into base 10 using that base and then convert back into binary and change the base to 2)
Binary(string binaryStr, int base = 2){
toDecimal();
}
void toBinary(){
binaryString = "";
int temp = decimalNo;
while(temp > 0){
binaryString = char(temp%2 + '0') + binaryString;
temp /= 2;
}
}
void toDecimal(){
decimalNo = 0;
for(int i=0;i<binaryString.length();i++) decimalNo += (binaryString[i] - '0')*pow(2, binaryString.length()-1-i);
}
// Overloading + operator for addition
Binary operator+(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo + other.decimalNo;
result.toBinary();
return result;
}
// Overloading - operator for subtraction
Binary operator-(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo - other.decimalNo;
result.toBinary();
return result;
}
// Overloading += operator for addition
Binary& operator+=(const Binary& other){
this->decimalNo += other.decimalNo;
this->toBinary();
return *this;
}
// Overloading -= operator for subtraction
Binary& operator-=(const Binary& other){
this->decimalNo -= other.decimalNo;
this->toBinary();
return *this;
}
// Overloading * operator for multiplication (Convert to base 10 multiply and convert back into base 2)
Binary operator*(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo * other.decimalNo;
result.toBinary();
return result;
}
// Overloading / operator for division (Convert to base 10 divide and convert back into base 2)
Binary operator/(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo / other.decimalNo;
result.toBinary();
return result;
}
// Overloading % operator for modulus (Convert to base 10 modulus and convert back into base 2)
Binary operator%(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo % other.decimalNo;
result.toBinary();
return result;
}
// Overloading | operator for or
Binary operator|(const Binary& other) const{
}
// Overloading ^ operator for xor
Binary operator^(const Binary& other) const{
}
// Overloading & operator for and
Binary operator&(const Binary& other) const{
}
// Overloading ! operator for 2's Compliment
Binary operator!() const{
}
// Overloading ~ operator for 1's Compliment
Binary operator~() const{
}
// Overloading left shift operator
Binary operator<<(int shiftAmount) const{
}
// Overloading right shift operator
Binary operator>>(int shiftAmount) const{
}
// Overloading input operator
friend istream& operator>>(istream& input, Binary& other){
}
// Overloading output operator (Display Both Binary as well as Integer value)
friend ostream& operator<<(ostream& output, const Binary& other){
}
};

View file

@ -0,0 +1,120 @@
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
class Binary {
private:
string binaryString;
int base;
int decimalNo;
public:
// Constructor (If base is greater than 2 first convert into base 10 using that base and then convert back into binary and change the base to 2)
Binary(string binaryStr, int base = 2){
toDecimal();
}
void toBinary(){
binaryString = "";
int temp = decimalNo;
while(temp > 0){
binaryString = char(temp%2 + '0') + binaryString;
temp /= 2;
}
}
void toDecimal(){
decimalNo = 0;
for(int i=0;i<binaryString.length();i++) decimalNo += (binaryString[i] - '0')*pow(2, binaryString.length()-1-i);
}
// Overloading + operator for addition
Binary operator+(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo + other.decimalNo;
result.toBinary();
return result;
}
// Overloading - operator for subtraction
Binary operator-(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo - other.decimalNo;
result.toBinary();
return result;
}
// Overloading += operator for addition
Binary& operator+=(const Binary& other){
this->decimalNo += other.decimalNo;
}
// Overloading -= operator for subtraction
Binary& operator-=(const Binary& other) const{
}
// Overloading * operator for multiplication (Convert to base 10 multiply and convert back into base 2)
Binary operator*(const Binary& other) const{
}
// Overloading / operator for division (Convert to base 10 divide and convert back into base 2)
Binary operator/(const Binary& other) const{
}
// Overloading % operator for modulus (Convert to base 10 modulus and convert back into base 2)
Binary operator%(const Binary& other) const{
}
// Overloading | operator for or
Binary operator|(const Binary& other) const{
}
// Overloading ^ operator for xor
Binary operator^(const Binary& other) const{
}
// Overloading & operator for and
Binary operator&(const Binary& other) const{
}
// Overloading ! operator for 2's Compliment
Binary operator!() const{
}
// Overloading ~ operator for 1's Compliment
Binary operator~() const{
}
// Overloading left shift operator
Binary operator<<(int shiftAmount) const{
}
// Overloading right shift operator
Binary operator>>(int shiftAmount) const{
}
// Overloading input operator
friend istream& operator>>(istream& input, Binary& other){
}
// Overloading output operator (Display Both Binary as well as Integer value)
friend ostream& operator<<(ostream& output, const Binary& other){
}
};

View file

@ -0,0 +1,123 @@
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
class Binary {
private:
string binaryString;
int base;
int decimalNo;
public:
// Constructor (If base is greater than 2 first convert into base 10 using that base and then convert back into binary and change the base to 2)
Binary(string binaryStr, int base = 2){
toDecimal();
}
void toBinary(){
binaryString = "";
int temp = decimalNo;
while(temp > 0){
binaryString = char(temp%2 + '0') + binaryString;
temp /= 2;
}
}
void toDecimal(){
decimalNo = 0;
for(int i=0;i<binaryString.length();i++) decimalNo += (binaryString[i] - '0')*pow(2, binaryString.length()-1-i);
}
// Overloading + operator for addition
Binary operator+(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo + other.decimalNo;
result.toBinary();
return result;
}
// Overloading - operator for subtraction
Binary operator-(const Binary& other) const{
Binary result("", 2);
result.decimalNo = this->decimalNo - other.decimalNo;
result.toBinary();
return result;
}
// Overloading += operator for addition
Binary& operator+=(const Binary& other){
this->decimalNo += other.decimalNo;
this->toBinary();
return *this;
}
// Overloading -= operator for subtraction
Binary& operator-=(const Binary& other){
this->decimalNo -= other.decimalNo;
this->toBinary();
return *this;
}
// Overloading * operator for multiplication (Convert to base 10 multiply and convert back into base 2)
Binary operator*(const Binary& other) const{
}
// Overloading / operator for division (Convert to base 10 divide and convert back into base 2)
Binary operator/(const Binary& other) const{
}
// Overloading % operator for modulus (Convert to base 10 modulus and convert back into base 2)
Binary operator%(const Binary& other) const{
}
// Overloading | operator for or
Binary operator|(const Binary& other) const{
}
// Overloading ^ operator for xor
Binary operator^(const Binary& other) const{
}
// Overloading & operator for and
Binary operator&(const Binary& other) const{
}
// Overloading ! operator for 2's Compliment
Binary operator!() const{
}
// Overloading ~ operator for 1's Compliment
Binary operator~() const{
}
// Overloading left shift operator
Binary operator<<(int shiftAmount) const{
}
// Overloading right shift operator
Binary operator>>(int shiftAmount) const{
}
// Overloading input operator
friend istream& operator>>(istream& input, Binary& other){
}
// Overloading output operator (Display Both Binary as well as Integer value)
friend ostream& operator<<(ostream& output, const Binary& other){
}
};