#include <iostream>
#include <vector>
#include <stack>
using namespace std;
void fConvert(long n, vector<long>& bit)
{
stack<long> tempstack;
long temp = n;
while (temp != 1)
{
long temp1 = temp % 2;
tempstack.push(temp1);
temp = temp / 2;
}
tempstack.push(1);
while (tempstack.empty() == false)
{
long n = tempstack.top();
bit.push_back(n);
tempstack.pop();
}
}
int main(int argc, char *argv)
{
vector<long> bit;
fConvert(10, bit);
vector<long>::iterator it = bit.begin();
while (it != bit.end())
{
cout << *it;
it++;
}
cout << endl;
system("pause");
return 0;
}
整数十进制转换成二进制
最新推荐文章于 2021-08-24 23:20:33 发布