zoukankan      html  css  js  c++  java
  • 十进制转二进制-高速算法

    #include<iostream>
    #include<string>
    #include<algorithm>
    using namespace std;
    int main(int agrc, char *agrv[])
    {
    	int iInPut = 0;
    	while (cin >> iInPut)
    	{
    
    		string sBinary;//转换后的二进制存储为字符串,调用了默认构造函数初试化为空串
    		int temp = abs(iInPut);
    		if (temp == 0)
    		{	
    			//cout.width(11);//以11位的宽度右对齐输出
    			cout << "          0-->0
    ";
    			continue;
    		}
    
    		while (temp)
    		{
    			if (temp & 0x01)
    			{
    				sBinary += '1';
    			}
    			else
    			{
    				sBinary += '0';
    			}
    			temp >>= 1;//对正数右移,高位补0
    		}
    		reverse(sBinary.begin(), sBinary.end());
    		const char *cOutPut = sBinary.c_str();
    		cout.width(11);
    		cout << iInPut << (iInPut > 0 ? "-->" : "-->-") << cOutPut << endl;
    	}
    	return 0;
    }

查看全文
  • 相关阅读:
    Java 获取当前时间最近12个月(字符串)
    Java 取本月第一天和最后一天
    find_in_set()和in()比较
    Latex 箭头、下标、符号上下写文字、正方形和三角形
    LaTeX 公式字体大小设置
    哈希学习(2)—— Hashing图像检索资源
    局部敏感哈希-Locality Sensitivity Hashing
    Mathtype 公式显示方框
    Linux下安装MATLAB
    局部敏感哈希(Locality-Sensitive Hashing, LSH)
  • 原文地址:https://www.cnblogs.com/ldxsuanfa/p/10783856.html
  • Copyright © 2011-2022 走看看