C++
xxxxxxxxxx
using namespace std;
int convertBinarytoOctal(long long);
int main()
{
long long binaryNumber;
cout << "Enter a binary number: ";
cin >> binaryNumber;
cout << binaryNumber << " in binary = " << convertBinarytoOctal(binaryNumber) << " in octal ";
return 0;
}
int convertBinarytoOctal(long long binaryNumber)
{
int octalNumber = 0, decimalNumber = 0, i = 0;
while(binaryNumber != 0)
{
decimalNumber += (binaryNumber%10) * pow(2,i);
++i;
binaryNumber/=10;
}
i = 1;
while (decimalNumber != 0)
{
octalNumber += (decimalNumber % 8) * i;
decimalNumber /= 8;
i *= 10;
}
return octalNumber;
}
Enter a binary number: 10001 10001 in binary = 21 in octal
Linux - How to Install anc-api-tools
Linux - How to Install curvedns
Linux - How to Install zenmap
Python - Check if a Number is Positive, Negative or 0
C - Count Number of Digits in an Integer
C++ - Check Whether a Number is Prime or Not
C - Find Largest Number Using Dynamic Memory Allocation
C++ - Check Leap Year
Kotlin - Reverse a Number
JavaScript - Check Whether a String Starts and Ends With Certain Characters
Linux - How to Install zstd
C++ - Find Quotient and Remainder
Linux - How to Install xbitmaps
Kotlin - Round a Number to n Decimal Places
Java - Reverse a Number
Kotlin - Find Factorial of a Number
Python - Writing Excel (XLSX) Files
Java - Create Pyramid and Pattern
We have been online since 2021 and 1 millions of people around the globe have visited our website since then
More visitors every month