Horje
convert decimal to binary in c++ Code Example
convert decimal to binary in c++
#include<iostream>
#include<vector>
using namespace std;

void Decimal_To_Binary(int num)
{
	string s;
	vector<int> v;
	int i = 0;
	while (num != 0)
	{
		
		v.push_back(num % 2);
		num /= 2;
		i++;
	}
	reverse(v.begin(), v.end());
	for (auto n : v)
	{
		cout << n;  
	}
	//or
	/*for (int i = 0; i<v.size(); i++)
	{
		cout<< v[i]; 
	}*/
}
int main()
{
	int  num;
	cin >> num;
	Decimal_To_Binary(num);
	
	return 0;
}
convert decimal to binary c++
- Convert decimal to binary string using std::bitset
int n = 10000;
string s = bitset<32>(n).to_string(); // 32 is size of n (int)




Cpp

Related
what is the associative property of an operator Code Example what is the associative property of an operator Code Example
rotate in c++ Code Example rotate in c++ Code Example
c++ return multiple values Code Example c++ return multiple values Code Example
unordered_set to vector Code Example unordered_set to vector Code Example
c++ linked list Code Example c++ linked list Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
11