十进制转各进制

// 十进制转化为各进制.cpp : Defines the entry point for the console application.
//


#include <iostream>
#include<cstdlib>
using namespace std;
int main()
{
while(1)
{
int input;
cout<<"请输入待转化的十进制数:"<<endl;
cin>>input;
int num2,num8,num10,bite_num2=1,bite_num8=1,bite_num10=1;
num2=num8=num10=input;
cout<<"请输入2,8,16以选择进行何种转化:"<<endl
"2:二进制,8:八进制,16:十六进制"<<endl;
int num_form;
cin>>num_form;
switch(num_form)
{
case 2:while(num2/2!=0)
  {
  num2=num2/2;
  ++bite_num2;
  }
char *bite2=new char[bite_num2];
itoa(input,bite2,2);
for(int i=0;i<bite_num2;i++)
cout<<bite2[i]; 
cout<<endl;
delete []bite2;break;
case 8:while(num8/8!=0)
  {
  num8=num8/2;
  ++bite_num8;
  }
char *bite8=new char[bite_num8];
itoa(input,bite8,8);
for(int i=0;i<bite_num8;i++)
cout<<bite8[i]; 
cout<<endl;
delete []bite8;break;
case 16:while(num16/2!=0)
  {
  num16=num16/2;
  ++bite_num16;
  }
char *bite16=new char[bite_num16];
itoa(input,bite16,16);
for(int i=0;i<bite_num16;i++)
cout<<bite16[i]; 
cout<<endl;
delete []bite16;
break;


}
}
return 0;
}
posted @ 2014-03-27 18:16  lz3018  阅读(164)  评论(0编辑  收藏  举报