wtorek, 30 sierpnia 2016

Sums modulo 2 and first numbers

#include <iostream>
#define max 10
#define two 2
using namespace std;

class Byte_First
{
private:
unsigned char tab[max];
unsigned char tab_traditional[max];
int *first_tab;
int *first_tab_traditional;
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;
}
public:
Byte_First()
{
int i,j;
first_tab=new int[max];
first_tab_traditional=new int[max];
i=0;j=1;
do
{
if(is_first(j))
{
first_tab[i]=j;
++i;
}
++j;
}while(i<max);
j=1;
for(i=0;i<max;i++)
{
tab[i]=first_tab[i];
first_tab_traditional[i]=j;
j*=two;
tab_traditional[i]=first_tab_traditional[i];
 
}

    }
    ~Byte_First()
    {
delete first_tab_traditional;
delete first_tab;
}
    void Write_Byte(int next_first)
    {
int i,j,my_byte;
for(i=max-1;i>=0;i--)
{
my_byte=(tab[i]&next_first);
if(my_byte!=0)
cout<<'1';
else
cout<<'0';
}

}
void Write_Byte_Traditional(int next_first)
{
int i,j,my_byte;
for(i=max-1;i>=0;i--)
{
my_byte=(tab_traditional[i]&next_first);
if(my_byte!=0)
cout<<'1';
else
cout<<'0';
}
}
void Show()
{
int i,j;
for(i=1;i<max+1;i++)
{
j=~i;
Write_Byte_Traditional(i); cout<<"\t"; Write_Byte(i);cout<<" negation ";Write_Byte_Traditional(j);cout<<"\t";Write_Byte(j);cout<<endl;
}
}

};

int main(int argc, char** argv)
{
Byte_First FF;
FF.Show();

return 0;
}

Brak komentarzy:

Prześlij komentarz