加载中…
个人资料
  • 博客等级:
  • 博客积分:
  • 博客访问:
  • 关注人气:
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

“二进制转换为任意进制”代码

(2007-06-16 22:59:53)
分类: 技术
觉的很久没发代码了。。。
下面的代码是二进制转换为任意进制,记得是上学期大个说找工作什么的叫我帮忙写的,当时赶时间,也就用个简单的容器来实现了,多指教!
其中具体的表示形式可以再稍做修改~
 
class CDec2Any{
    std::vector<short int> Cvec;
public:
    void Dec2Any(int&,int&);
};
void CDec2Any::Dec2Any(int& mNum, int& mType)
{
 if ( mNum / mType != 0 ){
      Cvec.push_back( mNum % mType );
      int temp = mNum/mType;
      Dec2Any(temp,mType);
 }
 else{
      Cvec.push_back( mNum % mType );
 }
}
……
//main.cpp
 int iNum,iType;
 CDec2Any a;
 cout<<"Input the number and the target format type you want to convert"<<endl;
 cin>>iNum>>iType;
 a.Dec2Any(iNum,iType);
for( vector<short int>::reverse_iterator iter = a.Cvec.rbegin(); iter != a.Cvec.rend(); ++iter ){
  cout<<*iter;
 }
 cout<<endl;
 

0

阅读 收藏 喜欢 打印举报/Report
前一篇:感悟人生
  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有