1 Replies - 5395 Views - Last Post: 29 November 2001 - 12:10 PM Rate Topic: -----

#1 miaka284  Icon User is offline

  • D.I.C Addict

Reputation: 0
  • View blog
  • 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  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 3
  • View blog
  • 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.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1