Make class BaraBitkaar as described in lecture to represent 16Byte or 128bit numbers. Make three functions as BitKaar of A8 i.e. PrintBinary(), PrintDecimal(), and PrintHexadecimal() respectively. Also make a member function SetValue(char * valuestring), that takes as parameter a 128 character string for example "11111111111100000000000001111111101010100101111111111111111111111111111111111111111111111111111111111011111101110101111101011011" containing the binary representation and sets the value of private members accordingly. Remember there is a member char var[16] which contains the binary value.work program output bitwise.
#include <iostream>
#include<math.h>
using namespace std;
class A8
{
public:
int num=679854635;
};
class decimal:public virtual A8
{
public:
int decimal;
void assign_num()
{
decimal=num*1.00;
}
void display1()
{
cout<<"\nDecimal:"<<decimal;
}
};
class hexadeciaml:public virtual A8
{
public:
char hexaDeciNum[100];
int i = 0;
int n=num;
void assign_num2()
{
while(n!=0)
{
int temp = 0;
temp = n % 16;
if(temp < 10)
{
hexaDeciNum[i] = temp + 48;
i++;
}
else
{
hexaDeciNum[i] = temp + 55;
i++;
}
n = n/16;
}
}
void display2()
{
cout<<"\n Hexa:";
for(int j=i-1; j>=0; j--)
cout << hexaDeciNum[j];
}
};
class binary:public virtual A8
{
public:
char binary[100];
int i = 0;
int n=num;
void assign_num3()
{
while(n!=0)
{
int temp = 0;
temp = n % 2;
if(temp < 10)
{
binary[i] = temp + 48;
i++;
}
n = n/2;
}
}
void display3()
{
cout<<"\n binary:";
for(int j=i-1; j>=0; j--)
cout << binary[j];
}
};
class data:public decimal,public hexadeciaml,public binary
{
public:
void assign()
{//decimal
assign_num();
display1();
//hexadeciaml
assign_num2();
display2();
//binary
assign_num3();
display3();
}
};
int main() {
std::cout << "Conversion\n";
data a;
a.assign();
}
Comments
Leave a comment