Exemplo n.º 1
0
 void _grayCode(std::vector<int> &ret, std::bitset<32> &bits, int pos) {
     if (pos == 0) {
         ret.push_back(static_cast<int>(bits.to_ulong()));
         return ;
     }
     _grayCode(ret, bits, n, pos - 1);
     bits.flip(pos - 1);
     _grayCode(ret, bits, n, pos - 1);
 }
Exemplo n.º 2
0
void Tarea3::on_pushButton_2_clicked()
{


    QString hey=ui->lineEdit_2->text();



    ifstream read2("bits");
    string line2;
    string numero;
    if(read2.is_open())
    {
        while (getline (read2,line2,'$').good())
        {
               QString ind=QString::fromStdString(line2);
               numero=ind.toStdString();
        }

    }
    read2.close();



    int indice=hey.toInt();
    std::bitset<32> b(numero);

    b.flip(indice-1);






    string mystring = b.to_string<char,char_traits<char>,allocator<char> >();
    QString show=QString::fromStdString(mystring);

     ui->listWidget->addItem(show);

     ofstream myfile2 ("bits",ios::out);
     std::cout<<mystring<<endl;
     myfile2<<mystring<<"$";

     myfile2.close();



//        in_use = in_use ^ 1<<toBit;



}
Exemplo n.º 3
0
  void rebuild()
  {
    p.reset();
    p.flip();

    p[0] = p[1] = 1;

    for ( size_t n=2; n < PRIMES; ++n )
      if ( p[n] ) {
        v.push_back(n);

        for ( size_t m=n<<1; m < PRIMES; m += n )
          p[m] = 0;
      }
  }
Exemplo n.º 4
0
void toggleDebugFlag(DebugFlags _flag) {

    g_flags.flip(_flag);
    m_view->setZoom(m_view->getZoom()); // Force the view to refresh

    // Rebuild tiles for debug modes that needs it
    if (_flag == DebugFlags::proxy_colors
     || _flag == DebugFlags::tile_bounds
     || _flag == DebugFlags::tile_infos) {
        if (m_tileManager) {
            std::lock_guard<std::mutex> lock(m_tilesMutex);
            m_tileManager->clearTileSets();
        }
    }
}
Exemplo n.º 5
0
void BSO::randomFlip(std::bitset<chromoLength> &paramsBS, int type)
{
	
	return; //no change

	int pos = 0;
	if(type == 0) //flip in all position
	{
		pos = rand()%chromoLength;
	}
	else if(type == 1)  //flip im only
	{
		pos = rand()%imLength;
	}
	else if(type == 2)  //flip pf only
	{
		pos = imLength + rand()%pfLength;
	}
	paramsBS = paramsBS.flip(pos);
}
Exemplo n.º 6
0
// For correctness check out:
// "A Linear Sieve Algorithm for Finding Prime Numbers" 
void generate_sieve()
{
    sieve.flip(); // all bits are 1 now
    for (int i=2; i<n; ++i){
        if (sieve[i]){
            primes.push_back(i);
        }
        for (int k=0; k<(int)primes.size() && i*primes[k]<n; ++k){
            // For debug purposes: 
            // std::cout<<"i="<<i<<", k="<<k<<", "<<i*primes[k]<<std::endl;

            // We reset the bit of a composite number, until we find lowest
            // prime that divides i.
            sieve.reset(i*primes[k]);
            if (i%primes[k] == 0){
                break;
            }
        } 
    } 
}
Exemplo n.º 7
0
void toggleDebugFlag(DebugFlags _flag) {

    g_flags.flip(_flag);
    m_view->setZoom(m_view->getZoom()); // Force the view to refresh

}
Exemplo n.º 8
0
inline void chk(int t){
    if(vis[t]&&!--cnt[W[t]]) --res;
    else if(!vis[t]&&!cnt[W[t]]++) ++res;
    vis.flip(t);
}