0

hello

i hope you can help me :icon_question:

i just want to know how to code binary value to decimal value using c++

im willing to wait for your response :)

thanks a lot

godspeed

4
Contributors
4
Replies
5
Views
9 Years
Discussion Span
Last Post by glecymay
0

Sorry, I can't understand your question.
Binary value... of what? The same counter-question about "to decimal value"...

0

nothing fancy, if you know how to convert a binary representation to decimal on paper...just implement that! i'd use a string to input 1's and 0's but you can use a long long or something using a simple algorithm to seperate digits:

#include <iostream>

using namespace std;

int main( void )
{
    long long num; int result = 0, pow = 1;
    cin >> num;
    while( num > 0 ) {
           result += ( num % 10 )*pow;
           pow <<= 1;
           num /= 10;
    }
    cout << result << endl;
    return 0;
}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.