C++ string类型转二进制

#include
using namespace std;

int main()
{
	string s = "abc";
	int x = 0;
	int a[0xFFFF];
	for (int i1 = 0; i1 < s.size(); i1++)
	{
		x = s[i1] - '0';
		int n, i, j = 0;
		i = x;
		while (i)
		{
			a[j] = i % 2;
			i /= 2;
			j++;
		}
		for (i = j - 1; i >= 0; i--)
			cout << a[i] ;
	}
}

运行结果为110001110010110011

你可能感兴趣的:(windows程序设计)