#include <iostream>
#include <string.h>
using namespace std;
class Binary
{
private:
char temp_values[10];
int my_byts;
public:
char *result;
char *negation;
Binary()
{
int i,j;
j=1;
for(i=0;i<10;i++)
{
temp_values[i]=j;
j*=2;
}
result=new char[10];
result[0]='0';
negation=new char[10];
negation[0]='1';
}
void read_Binary(char digit)
{
int i;
for(i=9;i>=0;i--)
{
my_byts=(temp_values[i] & digit);
if(my_byts!=0)
{
strcat(result,"1");
strcat(negation,"0");
}
else
{
strcat(result,"0");
strcat(negation,"1");
}
}
}
void write_Binary()
{
cout<<result;
}
void write_Negation()
{
cout<<negation;
}
~Binary()
{
delete negation;
delete result;
}
};
int my_first_digit[10];
char char_first_table[10];
bool is_First(int x)
{
int i,sum;
sum=0;
for(i=1;i<x+1;i++)
if(x%i==0)
++sum;
if(sum==2)
return true;
else
return false;
}
void init_my_first_Table()
{
int i,j;
i=0;
j=1;
do
{
if(is_First(j))
{
my_first_digit[i]=j;
++i;
}
++j;
}while(i<10);
for(i=0;i<10;i++)
char_first_table[i]=my_first_digit[i];
}
int main(int argc, char **argv)
{
Binary *binary_First=new class Binary[10];
int i;
init_my_first_Table();
for(i=0;i<10;i++)
{
binary_First[i].read_Binary(char_first_table[i]);
cout<<my_first_digit[i]<<" - ";
binary_First[i].write_Binary();cout<<" - ";
binary_First[i].write_Negation();
cout<<endl;
}
delete binary_First;
return 0;
}
Result for table[10] (first digit) binary and negation:
2 - 00000000010 - 11111111101
3 - 00000000011 - 11111111100
5 - 00000000101 - 11111111010
7 - 00000000111 - 11111111000
11 - 00000001011 - 11111110100
13 - 00000001101 - 11111110010
17 - 00000010001 - 11111101110
19 - 00000010011 - 11111101100
23 - 00000010111 - 11111101000
29 - 00000011101 - 11111100010
Brak komentarzy:
Prześlij komentarz