Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

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() << '
';
	return 0;
}
Source by www.cplusplus.com #
 
PREVIOUS NEXT
Tagged: #binary #int #bitset
ADD COMMENT
Topic
Name
4+2 =