# binary to decimal

Page 1 of 1

## 1 Replies - 5665 Views - Last Post: 29 November 2001 - 12:10 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'https://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=2454&amp;s=caf9fed0b604fe6328ce768b7141f60c&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 miaka284

Reputation: 0
• Posts: 530
• Joined: 10-May 01

# binary to decimal

Posted 29 November 2001 - 09:32 AM

ahh.. help please... I am trying to conver binary to decimal.. but everytime I enter the binary number for 1, it gives me 255.. and I don't know what's wrong with it.. could someone look at it for me please.. I would greatly appreciated..
```void binary()
{cout<<"Please enter 0's and 1's and maximum of 8 places, no decimal or negative numbers"<<endl;
cin.get(num,8);
cin.ignore(80,'
');
for(a=0;a<8;a++)
{
bnum[a]=atoi(num);}if(((bnum[0]*128)+(bnum[1]*64)+(bnum[2]*32)+(bnum[3]*16)+(bnum[4]*8)+(bnum[5]*4)+(bnum[6]*2)+(bnum[7]*1))>256)
{
cout<<" Sorry sir/ma'me, you've entered an invalid number please try again"<<endl;
binary();
}
else
{
bin=((bnum[0]*128)+(bnum[1]*64)+(bnum[2]*32)+(bnum[3]*16)+(bnum[4]*8)+(bnum[5]*4)+(bnum[6]*2)+(bnum[7]*1));
cout<<bin<<endl;
title();    }
}

```

(Edited by miaka284 at 9:40 am on Nov. 29, 2001)

Is This A Good Question/Topic? 0

## Replies To: binary to decimal

### #2 malkiri

• D.I.C Regular

Reputation: 3
• Posts: 364
• Joined: 29-March 01

## Re: binary to decimal

Posted 29 November 2001 - 12:10 PM

Your problem is in this block:
```for(a=0;a<8;a++)
{
bnum[a]=atoi(num);
}

```

Ponder it for a few and see what you come up with.