Answers for "binary to int c++ bitset"

C++
0

binary to int c++ bitset

#include <iostream>
#include <string>
#include <bitset>
 
int main()
{
	std::string s("100"); // 100 in binary is 4 in decimal
	// Note: You have to specify exactly how many bits you need
	std::bitset<sizeof(int) * 8> b(s);
	std::cout << b.to_ulong() << '\n';
	return 0;
}
Posted by: Guest on March-18-2022

Browse Popular Code Answers by Language