c++進制轉換

#include <iostream>
#include <stack>

void convert(std::stack<char> &s,__int64 n, int base)
{
	static char digit[] = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
	while (n > 0)
	{
		s.push(digit[n % base]);
		n /= base;
	}
}
int main()
{
	std::stack<char> s;
	convert(s,102413,16);
	int len = s.size();
	for (auto i = 0; i < len; i++)
	{
		std::cout<<s.top();
		s.pop();
	}
	std::cout<<std::endl;
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章