Program 6
To Lower Case
write logical part for the program to Convert Binary to Decimal by using the given function.
Example 1:
Input: “0001”
Output: “1”
Example 2:
Input: “0010”
Output: “2”
Example 3:
Input: “0100”
Output: “3”
Incorrect Code
Correct Code
Incorrect Code
Void binarytointeger(number)
{
// Type your code here
}
void main()
{
int num;
cin>>num;
binarytointeger(num);
}
Correct Code
void binarytointegerl(number)
{
int dval=0, base=1, rem;
while(number > 0)
{
rem = number % 10;
dval = dval + rem * base;
num = number / 10;
base = base * 2;
}
cout<>num;
binarytointeger(num);
return 0;
}

Login/Signup to comment