C++編程 進制轉換

#include <iostream>
using namespace std;
void decToBin(long x, char *a)
{
 ltoa(x, a, 2);
}
void hexToDec(char *a, long &x)
{
 x = strtol(a, (char**)NULL, 16);
}
int main()
{
 long x;
 char temp[255];
 cout << "輸入一個十進制數: ";
 cin >> x;
 decToBin(x, temp);
 cout << "轉換成二進制爲: " << temp << endl;

 cout << "輸入一個十六進制數: ";
 cin >> temp;
 hexToDec(temp, x);
 cout << "轉換爲十進制爲: " << x << endl;
 return 0;
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章