Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- // Function to convert binary to decimal
- int binaryToDecimal(int binNumber)
- {
- int decValue = 0;
- int base = 1; //основа - 2^0=1
- while (binNumber)
- {
- decValue += (binNumber & 1) * base;
- binNumber >>= 1;
- base *= 2;
- }
- return decValue;
- }
- // Driver program to test above function
- int main()
- {
- cout << binaryToDecimal(0b10000000000) << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment