How to check if specific bit in bitset is set with C++

2 Answers

0 votes
#include <iostream>
#include <bitset>
#include <string>

using std::cout;
using std::endl;

int main()
{
	std::bitset<16> bo(std::string("1011"));
	
	cout << bo << endl;

	if (bo[0] == 1)
		cout << "bit 0 is set" << endl;
	return 0;
}


/*
run:

0000000000001011
bit 0 is set

*/

 



answered Apr 18, 2018 by avibootz
0 votes
#include <iostream>
#include <bitset>
#include <string>

using std::cout;
using std::endl;

int main()
{
	std::bitset<16> bo(std::string("1011"));
	
	cout << bo << endl;

	if (bo.test(0) == 1)
		cout << "bit 0 is set" << endl;
	return 0;
}


/*
run:

0000000000001011
bit 0 is set

*/

 



answered Apr 18, 2018 by avibootz

Related questions

1 answer 273 views
1 answer 203 views
1 answer 216 views
1 answer 215 views
1 answer 175 views
1 answer 216 views
...