# Thread: Convert a binary number into a decimal number

1. ## Convert a binary number into a decimal number

Here's the part of the codes where I tried to use boolean expression:

Code:
```#include <iostream>
using namespace std;
int main()
{
int num;
cout << "8-bit Binary Number=";
cin >> num;

bool valid = true;
.
.
.
.
.
.
.
.
.
if (valid)
{
cout << "Decimal Number = " << sum;
}
}```
May I know that how can I get started with the body?

Thanks for your guides!

2. May I know that how can I get started with the body?
The expected behavior is not clear. Please provide input and corresponding output examples.

3. Unless you have a design in mind, start with a flowchart to flesh out the logic.

4. Note the default for cin and cout is to input and output decimal strings, while the numbers are stored internally as binary numbers. So it appears that your program will input a decimal string into a binary number, then convert the number as if the input was a binary string. You'll have to assume the user only input the characters '0' and '1' for the number. The program could input a string, then convert that string into a number.

5. Hi guys, thanks for your replies!
These are the output expected from me,
case 1:
8-bit Binary Number= 11111111
Decimal Number = 255

case2:
8-bit Binary Number=10101010
Decimal Number = 170

case 3:
8-bit Binary Number=101010102
Number entered is not a binary number

6. The program should input a string.

7. Hi there, I bet you're an IT student from MMU .Right? =P

8. i Bet it too

Popular pages Recent additions