27 Mart 2017 Pazartesi

QT BINARY CONVERT TO DECIMAL

#include "binary_convert.h"
#include
Binary_Convert::Binary_Convert()
{

}
void Binary_Convert::bin_con()
{

    int num,binary_val ,decimal=0,base=1,rem;
    std::cout << " Please Binary Value : ";
    std::cin>>num;
    binary_val=num;

    while(num>0)
    {
        rem=num%10;
        decimal=decimal+rem*base;
        num=num/10;
        base=base*2;
    }
    std::cout << "\n Binary Value is   : "<< binary_val;
    std::cout<<  "\n Decimal Value is  : "<< decimal;


}
Share: