test
This commit is contained in:
parent
37776af5db
commit
ab03d5f10c
4045 changed files with 286212 additions and 3 deletions
137
.config/Code/User/History/15e980f8/0AHD.cpp
Normal file
137
.config/Code/User/History/15e980f8/0AHD.cpp
Normal 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){
|
||||
|
||||
}
|
||||
};
|
142
.config/Code/User/History/15e980f8/0PlU.cpp
Normal file
142
.config/Code/User/History/15e980f8/0PlU.cpp
Normal 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){
|
||||
|
||||
}
|
||||
};
|
142
.config/Code/User/History/15e980f8/10pm.cpp
Normal file
142
.config/Code/User/History/15e980f8/10pm.cpp
Normal 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){
|
||||
|
||||
}
|
||||
};
|
119
.config/Code/User/History/15e980f8/1BYE.cpp
Normal file
119
.config/Code/User/History/15e980f8/1BYE.cpp
Normal 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){
|
||||
|
||||
}
|
||||
};
|
135
.config/Code/User/History/15e980f8/21tk.cpp
Normal file
135
.config/Code/User/History/15e980f8/21tk.cpp
Normal 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){
|
||||
|
||||
}
|
||||
};
|
155
.config/Code/User/History/15e980f8/4uEo.cpp
Normal file
155
.config/Code/User/History/15e980f8/4uEo.cpp
Normal 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){
|
||||
|
||||
}
|
||||
};
|
158
.config/Code/User/History/15e980f8/5Wej.cpp
Normal file
158
.config/Code/User/History/15e980f8/5Wej.cpp
Normal 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){
|
||||
|
||||
}
|
||||
};
|
121
.config/Code/User/History/15e980f8/5gO0.cpp
Normal file
121
.config/Code/User/History/15e980f8/5gO0.cpp
Normal 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){
|
||||
|
||||
}
|
||||
};
|
172
.config/Code/User/History/15e980f8/6Kb9.cpp
Normal file
172
.config/Code/User/History/15e980f8/6Kb9.cpp
Normal 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;
|
||||
}
|
175
.config/Code/User/History/15e980f8/8gsa.cpp
Normal file
175
.config/Code/User/History/15e980f8/8gsa.cpp
Normal 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;
|
||||
}
|
142
.config/Code/User/History/15e980f8/9qgS.cpp
Normal file
142
.config/Code/User/History/15e980f8/9qgS.cpp
Normal 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){
|
||||
|
||||
}
|
||||
};
|
137
.config/Code/User/History/15e980f8/DK8B.cpp
Normal file
137
.config/Code/User/History/15e980f8/DK8B.cpp
Normal 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){
|
||||
|
||||
}
|
||||
};
|
175
.config/Code/User/History/15e980f8/I0es.cpp
Normal file
175
.config/Code/User/History/15e980f8/I0es.cpp
Normal 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;
|
||||
}
|
115
.config/Code/User/History/15e980f8/JlfZ.cpp
Normal file
115
.config/Code/User/History/15e980f8/JlfZ.cpp
Normal 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){
|
||||
|
||||
}
|
||||
};
|
178
.config/Code/User/History/15e980f8/N5qt.cpp
Normal file
178
.config/Code/User/History/15e980f8/N5qt.cpp
Normal 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;
|
||||
}
|
166
.config/Code/User/History/15e980f8/NGXH.cpp
Normal file
166
.config/Code/User/History/15e980f8/NGXH.cpp
Normal 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){
|
||||
|
||||
}
|
113
.config/Code/User/History/15e980f8/NbDT.cpp
Normal file
113
.config/Code/User/History/15e980f8/NbDT.cpp
Normal 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){
|
||||
|
||||
}
|
||||
};
|
142
.config/Code/User/History/15e980f8/PTuU.cpp
Normal file
142
.config/Code/User/History/15e980f8/PTuU.cpp
Normal 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){
|
||||
|
||||
}
|
||||
};
|
126
.config/Code/User/History/15e980f8/Q0vt.cpp
Normal file
126
.config/Code/User/History/15e980f8/Q0vt.cpp
Normal 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){
|
||||
|
||||
}
|
||||
};
|
137
.config/Code/User/History/15e980f8/Rzv3.cpp
Normal file
137
.config/Code/User/History/15e980f8/Rzv3.cpp
Normal 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){
|
||||
|
||||
}
|
||||
};
|
142
.config/Code/User/History/15e980f8/T8x1.cpp
Normal file
142
.config/Code/User/History/15e980f8/T8x1.cpp
Normal 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){
|
||||
|
||||
}
|
||||
};
|
162
.config/Code/User/History/15e980f8/Tyn6.cpp
Normal file
162
.config/Code/User/History/15e980f8/Tyn6.cpp
Normal 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){
|
||||
|
||||
}
|
115
.config/Code/User/History/15e980f8/XB7y.cpp
Normal file
115
.config/Code/User/History/15e980f8/XB7y.cpp
Normal 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){
|
||||
|
||||
}
|
||||
};
|
133
.config/Code/User/History/15e980f8/XNyE.cpp
Normal file
133
.config/Code/User/History/15e980f8/XNyE.cpp
Normal 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){
|
||||
|
||||
}
|
||||
};
|
138
.config/Code/User/History/15e980f8/ZP9f.cpp
Normal file
138
.config/Code/User/History/15e980f8/ZP9f.cpp
Normal 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){
|
||||
|
||||
}
|
||||
};
|
167
.config/Code/User/History/15e980f8/ZTyJ.cpp
Normal file
167
.config/Code/User/History/15e980f8/ZTyJ.cpp
Normal 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: ";
|
||||
}
|
152
.config/Code/User/History/15e980f8/aoEF.cpp
Normal file
152
.config/Code/User/History/15e980f8/aoEF.cpp
Normal 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){
|
||||
|
||||
}
|
||||
};
|
115
.config/Code/User/History/15e980f8/avdL.cpp
Normal file
115
.config/Code/User/History/15e980f8/avdL.cpp
Normal 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){
|
||||
|
||||
}
|
||||
};
|
113
.config/Code/User/History/15e980f8/b2Af.cpp
Normal file
113
.config/Code/User/History/15e980f8/b2Af.cpp
Normal 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){
|
||||
|
||||
}
|
||||
};
|
164
.config/Code/User/History/15e980f8/bsMW.cpp
Normal file
164
.config/Code/User/History/15e980f8/bsMW.cpp
Normal 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){
|
||||
|
||||
}
|
172
.config/Code/User/History/15e980f8/c1DH.cpp
Normal file
172
.config/Code/User/History/15e980f8/c1DH.cpp
Normal 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;
|
||||
}
|
142
.config/Code/User/History/15e980f8/cMB0.cpp
Normal file
142
.config/Code/User/History/15e980f8/cMB0.cpp
Normal 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){
|
||||
|
||||
}
|
||||
};
|
1
.config/Code/User/History/15e980f8/entries.json
Normal file
1
.config/Code/User/History/15e980f8/entries.json
Normal 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}]}
|
162
.config/Code/User/History/15e980f8/fbHV.cpp
Normal file
162
.config/Code/User/History/15e980f8/fbHV.cpp
Normal 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){
|
||||
|
||||
}
|
146
.config/Code/User/History/15e980f8/gFSR.cpp
Normal file
146
.config/Code/User/History/15e980f8/gFSR.cpp
Normal 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){
|
||||
|
||||
}
|
||||
};
|
123
.config/Code/User/History/15e980f8/gLdN.cpp
Normal file
123
.config/Code/User/History/15e980f8/gLdN.cpp
Normal 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){
|
||||
|
||||
}
|
||||
};
|
133
.config/Code/User/History/15e980f8/jFzl.cpp
Normal file
133
.config/Code/User/History/15e980f8/jFzl.cpp
Normal 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){
|
||||
|
||||
}
|
||||
};
|
168
.config/Code/User/History/15e980f8/k4Kr.cpp
Normal file
168
.config/Code/User/History/15e980f8/k4Kr.cpp
Normal 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: ";
|
||||
|
||||
}
|
176
.config/Code/User/History/15e980f8/kdtH.cpp
Normal file
176
.config/Code/User/History/15e980f8/kdtH.cpp
Normal 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;
|
||||
}
|
173
.config/Code/User/History/15e980f8/lX80.cpp
Normal file
173
.config/Code/User/History/15e980f8/lX80.cpp
Normal 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;
|
||||
}
|
172
.config/Code/User/History/15e980f8/mGn6.cpp
Normal file
172
.config/Code/User/History/15e980f8/mGn6.cpp
Normal 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;
|
||||
}
|
155
.config/Code/User/History/15e980f8/nYHN.cpp
Normal file
155
.config/Code/User/History/15e980f8/nYHN.cpp
Normal 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);
|
||||
|
||||
};
|
167
.config/Code/User/History/15e980f8/o8zr.cpp
Normal file
167
.config/Code/User/History/15e980f8/o8zr.cpp
Normal 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;
|
||||
}
|
113
.config/Code/User/History/15e980f8/pkgm.cpp
Normal file
113
.config/Code/User/History/15e980f8/pkgm.cpp
Normal 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){
|
||||
|
||||
}
|
||||
};
|
173
.config/Code/User/History/15e980f8/s5JJ.cpp
Normal file
173
.config/Code/User/History/15e980f8/s5JJ.cpp
Normal 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;
|
||||
}
|
167
.config/Code/User/History/15e980f8/szWx.cpp
Normal file
167
.config/Code/User/History/15e980f8/szWx.cpp
Normal 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){
|
||||
|
||||
}
|
142
.config/Code/User/History/15e980f8/tlQa.cpp
Normal file
142
.config/Code/User/History/15e980f8/tlQa.cpp
Normal 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){
|
||||
|
||||
}
|
||||
};
|
149
.config/Code/User/History/15e980f8/wbAx.cpp
Normal file
149
.config/Code/User/History/15e980f8/wbAx.cpp
Normal 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){
|
||||
|
||||
}
|
||||
};
|
132
.config/Code/User/History/15e980f8/xFP9.cpp
Normal file
132
.config/Code/User/History/15e980f8/xFP9.cpp
Normal 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){
|
||||
|
||||
}
|
||||
};
|
120
.config/Code/User/History/15e980f8/xJe7.cpp
Normal file
120
.config/Code/User/History/15e980f8/xJe7.cpp
Normal 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){
|
||||
|
||||
}
|
||||
};
|
123
.config/Code/User/History/15e980f8/xyLq.cpp
Normal file
123
.config/Code/User/History/15e980f8/xyLq.cpp
Normal 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){
|
||||
|
||||
}
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue