Decimal to binary conversion algorithm in C++

preview_player
Показать описание
Learn how to convert decimal numbers to binary numbers in C++. The decimal to binary algorithm in this C++ programming tutorial shows you how to perform the conversion using a vector or a string.
Рекомендации по теме
Комментарии
Автор

Actual coding of the algorithm starts at 2:29.

nextrie
Автор

Thank you very much! You are great at teaching!

lazizaakramova
Автор

Hi,
Actually, I am asked to convert decimal to binary but binary reverse meaning if its 95 decimal then the binary is but the output should be in reverse as and I am not allowed to use #include <vector>. I am reading my decimal number from an outside file.
can you please help me out if you can?
thanks

ravinderpalmahal
Автор

The compiler gives me an error saying :‘to_string’ was not declared in this scope

HerLove
Автор

the compiler give soo many errors and don't allow to use vector<int>

shamirabbas
Автор

How about code "number & >> i)"?

PGStudio_tech_games
Автор

#include <iostream>
using namespace std;
int main() {
int n;
cout<<"Start ";
cin >> n;
long ans = 0, temp = 1;
for (int x = 0; n > 0 ; n = n/2)
{
x = n % 2;
ans = ans + (x * temp);
temp = temp * 10;
}

cout << ans;
}

threalbatman