当前位置: 首页>>代码示例>>C++>>正文


C++ bitset::test方法代码示例

本文整理汇总了C++中std::bitset::test方法的典型用法代码示例。如果您正苦于以下问题:C++ bitset::test方法的具体用法?C++ bitset::test怎么用?C++ bitset::test使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在std::bitset的用法示例。


在下文中一共展示了bitset::test方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1:

std::vector<std::bitset<ROUND_KEY_SIZE> > generate_round_keys(const std::bitset<KEY_SIZE>& key) {
	std::vector<std::bitset<ROUND_KEY_SIZE> > round_keys;
	// split key into lower and upper half, of 28b
	std::bitset<KEY_SIZE/2> lower;
	std::bitset<KEY_SIZE/2> upper;
	int mid = key.size() / 2;
	for (int i = 0; i < key.size(); i++)
		if (i < mid) lower.set(i, key.test(i));
		else upper.set(i % mid, key.test(i));

	for (int i = 0; i < ROUND_NUM; ++i) {
		// left shift using key_schedule
		lower = (lower << key_schedule[i]);
		upper = (upper << key_schedule[i]);
		// permute using pc_2 table
		
		//combine 28b lower and 28b upper for 56b key
		std::bitset<KEY_SIZE> input_key;
		for (i = 0; i < input_key.size(); ++i) {
			if (i < mid) input_key.set(i, lower.test(i));
			else input_key.set(i, upper.test(i % mid));
		}
		
		// permute using pc_2 table
		std::bitset<ROUND_KEY_SIZE> round_key;
		for (int i = 0; i < pc_2.size(); ++i)
			round_key.set(i, input_key[pc_2[i]]);

		round_keys.push_back(round_key);
	}
	
	return round_keys;
}
开发者ID:noreirik,项目名称:dat510,代码行数:33,代码来源:Feistel_cipher.cpp

示例2: encrypt

// given plain text and key, return cipher text
std::bitset<BLOCK_SIZE> encrypt(const std::bitset<BLOCK_SIZE>& input_text, const std::bitset<INPUT_KEY_SIZE>& input_key, bool encrypt) {
	std::bitset<BLOCK_SIZE> cipher_block;	
	// generate initial key	
	std::bitset<KEY_SIZE> initial_key = generate_initial_key(input_key);
	
	// generate round keys
	std::vector<std::bitset<ROUND_KEY_SIZE> > round_keys = generate_round_keys(initial_key);
	
	// split input text into two blocks of 32b
	std::bitset<BLOCK_SIZE/2> lower; // use lower to represent bits [0,BLOCK_SIZE/2), and
	std::bitset<BLOCK_SIZE/2> upper; // user upper to represent bits [BLOCK_SIZE/2,BLOCK_SIZE)
	int mid = input_text.size() / 2;
	for (int i = 0; i < input_text.size(); i++)
		if (i < mid) lower.set(i, input_text.test(i));
		else upper.set(i % mid, input_text.test(i));
	
	std::bitset<BLOCK_SIZE/2> temp; // temporarily hold lower, so that upper can be used in XOR
	
	// if encryption
	if (encrypt) {
		for (int i = 0; i < ROUND_NUM; ++i) {
			//std::cout << "ROUND " << i << "----------------------------------------" << std::endl;
			//std::cout << "Using key " <<  i << ":\t\t" << round_keys[i] << std::endl;
			temp = copy_bit_pattern(lower); // hold r_i-1 in temp
			lower = perform_round(lower, round_keys[i]);
			lower ^= upper; // r_i = f(r_i-1,key) xor l_i-1
			upper = copy_bit_pattern(temp); // l_i = r_i-1
			std::cout << "ROUND " << i << " ENDED" << "----------------------------------" << std::endl;
		}
	} else {
		// if decryption
		for (int i = ROUND_NUM -1; i >= 0; --i) {
			//std::cout << "ROUND " << i << "----------------------------------------" << std::endl;
			//std::cout << "Using key " <<  i << ":\t\t" << round_keys[i] << std::endl;
			temp = copy_bit_pattern(lower); // hold r_i-1 in temp
			lower = perform_round(lower, round_keys[i]);
			lower ^= upper; // r_i = f(r_i-1,key) xor l_i-1
			upper = copy_bit_pattern(temp); // l_i = r_i-1
			//std::cout << "ROUND " << i << " ENDED" << "----------------------------------" << std::endl;
		}
	}
	
	// perform final swap
	for (int i = 0; i < cipher_block.size(); ++i) {
		if (i < mid) cipher_block.set(i, upper.test(i));
		else cipher_block.set(i, lower.test(i % mid));
	}
	
	return cipher_block;
}
开发者ID:noreirik,项目名称:dat510,代码行数:51,代码来源:Feistel_cipher.cpp

示例3: choose_threads

void Sync::choose_threads(){
    int ref = -1;
    for (UINT ii=0; ii<num_threads; ii++){
        unsigned int i = (ii + rrcounter) % num_threads;
        if ( !t[i].ignore && !was_executed.test(i) ){
            ref = i;
            break;
        }
    }
    if (ref == -1){
        was_executed.reset();
        for (UINT ii=0; ii<num_threads; ii++){
            unsigned int i = (ii + rrcounter) % num_threads;
            if (!t[i].ignore){
                ref = i;
                break;
            }
        }
    }
    
    for (UINT i=0; i<num_threads; i++){
        t[i].is_active = !t[i].ignore && t[i].pc == t[ref].pc;
        if (t[i].is_active){
            was_executed.set(i);
        }
    }
    
    // Next
    rrcounter = (ref + 1) % num_threads;
}
开发者ID:dougct,项目名称:mmt-sync,代码行数:30,代码来源:RoundRobin_Eq.cpp

示例4: expect_eq_set

void expect_eq_set(
    std::string label,
    std::bitset<BITS> bset,
    quadset<BITS> quad
) {
  for (bitpos i = 0; i < BITS; ++i) {
    EXPECT_EQ((bset.test(i)?1000:0)+i, (quad.test(i)?1000:0)+i) << label;
  }
}
开发者ID:perlmonger42,项目名称:hex-cpp,代码行数:9,代码来源:quadset_test.cpp

示例5: is_status_cinal

int eNFA::is_status_cinal(std::bitset<100> state)
{
	int status = 0;

	for ( int s=0; s < 100; ++s )
	{
		if ( state.test(s) )
			status |= _table[s].first;
	}

	return status;
}
开发者ID:dummer,项目名称:Automata,代码行数:12,代码来源:automata.cpp

示例6: do_test

bool OPKiller::do_test(const base_packet *p) {
    //~ Test namespace first.
    int area = p->ns();
    if (!areas_filter_.test(area & BLOOM_FILTER_MASK)) {
        return true;
    }
    if (target_areas_.find(area) == target_opcodes_.end()) {
        return true;
    }

    int opcode = p->getPCode();
    if (!opcodes_filter_.test(opcode & BLOOM_FILTER_MASK)) {
        return true;
    }
    if (target_opcodes_.find(opcode) == target_opcodes_.end()) {
        return true;
    }

    log_info("op[%d] of area[%d] refused.", opcode, area);
    return false;
}
开发者ID:alibaba,项目名称:tair,代码行数:21,代码来源:op_killer.hpp

示例7: IsBitset

bool AxString::IsBitset(std::bitset<256> &filter)
{
   if (IsEmpty()) 
      return false;

   for (char *cpos = (char *) m_pByteArray; *cpos; cpos++) {
      if (false == filter.test((unsigned char)(*cpos & 0xff))) {
         return false;
      }
   }

   return true;
}
开发者ID:tonymailxx,项目名称:rcsgrep,代码行数:13,代码来源:AxString.cpp

示例8: flip

int flip()
{
	int loop_count = 0;

	while(!stat_queue.empty())
	{
		loop_count++;
		unsigned long stat = stat_queue.front();
		stat_queue.pop();
		if(finished(stat))
		{
			int steps = 0;
			while(path[stat] != 0)
			{
				++steps;
				stat = path[stat];
			}
			printf("%d", steps);
			return 0;
		}
		int xPos, yPos;
		for(xPos = 0; xPos < N; ++xPos)
		{
			for(yPos = 0; yPos < N; ++yPos)
			{
				int i;
				std::bitset < 16 > next_stat(stat);
				for(i = 0; i < 5; ++i)
				{
					if(is_legal_position(xPos + move[i][0], yPos + move[i][1]) )
					{
						next_stat.flip((xPos + move[i][0]) * N + (yPos + move[i][1]) );
					}

				}

				//printf("%d\n", next_stat.to_ulong());
				unsigned long num_status = next_stat.to_ulong();
				if(!status_set.test(num_status))
				{
					status_set.set(num_status);
					//remember where current status comes from.
					path[num_status] = stat;
					stat_queue.push(num_status);
				}
			}
		}
	}
	printf("Impossible");
	return -1;
}
开发者ID:jflyup,项目名称:POJ,代码行数:51,代码来源:poj1753.cpp

示例9: insert_assertions_step

void insert_assertions_step(const php::Func& func,
                            const Bytecode& bcode,
                            const State& state,
                            std::bitset<kMaxTrackedLocals> mayReadLocalSet,
                            bool lastStackOutputObvious,
                            Gen gen) {
  for (size_t i = 0; i < state.locals.size(); ++i) {
    if (options.FilterAssertions) {
      if (i < mayReadLocalSet.size() && !mayReadLocalSet.test(i)) {
        continue;
      }
    }
    auto const realT = state.locals[i];
    auto const op = makeAssert<bc::AssertObjL,bc::AssertTL>(
      borrow(func.locals[i]), realT
    );
    if (op) gen(*op);
  }

  if (!options.InsertStackAssertions) return;

  // Skip asserting the top of the stack if it just came immediately
  // out of an 'obvious' instruction.  (See hasObviousStackOutput.)
  assert(state.stack.size() >= bcode.numPop());
  auto i = size_t{0};
  auto stackIdx = state.stack.size() - 1;
  if (lastStackOutputObvious) {
    ++i, --stackIdx;
  }

  /*
   * This doesn't need to account for ActRecs on the fpiStack, because
   * no instruction in an FPI region can ever consume a stack value
   * from above the pre-live ActRec.
   */
  for (; i < bcode.numPop(); ++i, --stackIdx) {
    auto const realT = state.stack[stackIdx];

    if (options.FilterAssertions &&
        !realT.strictSubtypeOf(stack_flav(realT))) {
      continue;
    }

    auto const op = makeAssert<bc::AssertObjStk,bc::AssertTStk>(
      static_cast<int32_t>(i), realT
    );
    if (op) gen(*op);
  }
}
开发者ID:2bj,项目名称:hhvm,代码行数:49,代码来源:optimize.cpp

示例10:

void NavFramer::Subframe::load(const std::bitset<5 * 300>& bs)
{
   bitset<30> word;
   for (int w=0; w<10; w++)
   {
      for(int b=0; b<30; b++)
         word[29-b] = bs.test((ni + w*30 + b)%1500);
      
      if (inverted)
         word = ~word;

      words[w] = word.to_ulong();
   }
   complete = true;
}
开发者ID:loongfee,项目名称:ossim-svn,代码行数:15,代码来源:NavFramer.cpp

示例11: Open

bool File::Open(std::string aFileName, std::bitset<8> aSetOfFlags)
{
	if(myFile != NULL)
	{
		return false;
	}
	std::string flags;
	if(aSetOfFlags.test(READ))
	{
		if(aSetOfFlags.test(WRITE))
		{
			flags += "r+";
		}
		else
		{
			flags += "r";
		}
	}
	else
	{
		if(aSetOfFlags.test(WRITE))
		{
			if(aSetOfFlags.test(APPEND))
			{
				flags += "a+";
			}
			else
			{
				flags += "w";
			}
		}
		else
		{
			assert(aSetOfFlags.test(APPEND));
			flags += "a";
		}
	}
	if(aSetOfFlags.test(BINARY))
	{
		flags += "b";
	}
	myFile = fopen(aFileName.c_str(), flags.c_str());
	myFlags = aSetOfFlags;

	if(myFile == NULL)
	{
		return false;
	}

	fseek(myFile , 0 , SEEK_END);
	mySize = ftell (myFile);
	rewind (myFile);

	return true;
}
开发者ID:TricycleCavalry,项目名称:CodeWars,代码行数:55,代码来源:FI_File.cpp

示例12: OnUserConnect

	void OnUserConnect(LocalUser* user)
	{
		ConfigTag* tag = user->MyClass->config;
		std::string vhost = tag->getString("vhost");
		std::string replace;

		if (vhost.empty())
			return;

		replace = "$ident";
		if (vhost.find(replace) != std::string::npos)
		{
			std::string ident = user->ident;
			if (ident[0] == '~')
				ident.erase(0, 1);

			SearchAndReplace(vhost, replace, ident);
		}

		replace = "$account";
		if (vhost.find(replace) != std::string::npos)
		{
			std::string account = GetAccount(user);
			if (account.empty())
				account = "unidentified";

			SearchAndReplace(vhost, replace, account);
		}

		if (vhost.length() > 64)
		{
			ServerInstance->Logs->Log("m_conn_vhost", DEFAULT, "m_conn_vhost: vhost in connect block %s is too long", user->MyClass->name.c_str());
			return;
		}

		/* from m_sethost: validate the characters */
		for (std::string::const_iterator x = vhost.begin(); x != vhost.end(); x++)
		{
			if (!hostmap.test(static_cast<unsigned char>(*x)))
			{
				ServerInstance->Logs->Log("m_conn_vhost", DEFAULT, "m_conn_vhost: vhost in connect block %s has invalid characters", user->MyClass->name.c_str());
				return;
			}
		}

		user->ChangeDisplayedHost(vhost.c_str());
	}
开发者ID:aszrul,项目名称:inspircd-extras,代码行数:47,代码来源:m_conn_vhost.cpp

示例13: printf

/* search_missing_combinations: traverse the BitTable
 * to find 0 bits and print out the corresponding
 * character sequences */
void
search_missing_combinations () {
    unsigned long missing_combs = 0;
    char buf[APPEARS_SEQSIZE + 1];
    for (unsigned long i = 0; i < TABLESIZE; i++) {
        if (!BitTable.test(i)) {
            index_to_tokens(i, buf);
            printf("  %s (index %lu)\n", buf, i);
            missing_combs++;
        }
    }
    if (missing_combs) {
        printf("For total %lu missing combinations found.\n",
                missing_combs);
    } else {
        printf("All combinations have appeared.\n");
    }
}
开发者ID:agentzh,项目名称:appears,代码行数:21,代码来源:appears.cpp

示例14: main

int main()
{
    generate_sieve();

    long long result = 0;
    for (auto prime : primes) {
        int n = prime - 1;
        bool valid = true;
        for (int d=1; d*d<=n && valid; ++d) {
            if (n%d == 0) {
                valid &= sieve.test(d + n / d);
            }
        }
        if (valid) {
            result += n;
        }
    }

    std::cout << result << std::endl;
    return 0;
}
开发者ID:sagi,项目名称:contests,代码行数:21,代码来源:p357.cpp

示例15: timer

std::pair<Matrix, std::vector<Label>> filterDataset(const Matrix &A, const std::vector<Label> &labels, const std::bitset<K> &filter) {
    Timer timer("Filter Dataset Timer");

    if (K < labels.size() || filter.count() <= 1) {
        std::stringstream fmt;
        fmt << "Filtro para el dataset tiene tamaño " << K << " cuando el dataset tiene tamaño " << labels.size();
        throw new std::invalid_argument(fmt.str());
    }

    std::vector<Label> output(filter.count(), 0.0);
    int last = 0;

    for (int i = 0; i < A.rows(); ++i) {
        if (filter.test((std::size_t) i)) {
            output[last] = labels[i];
            last++;
        }
    }

    return std::pair<Matrix, std::vector<Label>>(Matrix(A, filter), output);
}
开发者ID:maanuel,项目名称:metnum-tp2,代码行数:21,代码来源:main.cpp


注:本文中的std::bitset::test方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。