⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 assignmen 3-2 - binary2.cpp

📁 this code is code c++. have many lesson
💻 CPP
字号:
#include<iostream>
#include<string>

using namespace std;

int main()
{

	string input,output = "";
	int output2=0;
	int temp=128,ans = 0,temp2=0;
	int input2 = 0;

	cout << "Enter a number : " ;
	cin >> input;
	if(input.at(0)== '-')
	{
		input = input.substr(1,input.length()-1);
		for(int i = input.length()-1;i >=0;i--)
		{
			temp2 = input.at(i)-48;
			for(int j = input.length()-i-1;j > 0;j--)
			{
				temp2 *= 10;
			}     
			output2 += temp2;
		}
		output2 *= -1;
	}       

	else
	{  
		for(int i = input.length()-1;i >=0;i--)
		{
			temp2 = input.at(i)-48;
			for(int j = input.length()-i-1;j>0;j--)
			{
				temp2 *= 10;
			}     
			output2 += temp2;
		}
	}

cout << output2;






	if(output2 < 0){
		output += "1";
		output2 += 128; // plussssss

		for(temp = 64;temp > 0;temp /= 2){
			if(output2/temp == 1)
			{
				output2 %= temp;
				output += "1";        
			} else {
				output += "0";       
			}
		}

	}

	else
	{
		for(temp = 128;temp > 0;temp /= 2){
			if(output2/temp == 1)
			{
				output2 %= temp;
				output += "1";        
			} else {
				output += "0";       
			}
		}
	}
	cout << "The decimal number : " << output << endl;




	system("PAUSE");
	return 0;    
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -