can somebody teach me or show me a code that converts a binary to a decimal.... >_<
and if you could kindly explain how it happens.... should be in TurboC programming....

Recommended Answers

1010 in decimal =

1 * 2^3 + 0 * 2^2 + 1* 2^1 + 0*2^0 =

8 + 0 + 2 + 0 = 10

Thus 1010 in decimal is 10.

Jump to Post

All 2 Replies

1010 in decimal =

1 * 2^3 + 0 * 2^2 + 1* 2^1 + 0*2^0 =

8 + 0 + 2 + 0 = 10

Thus 1010 in decimal is 10.

#include<iostream>
#include<bitset>

int main()
{
  bitset<8> num;
  cin>>num;
  cout<<num.to_ulong();
}

}

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.