Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions Cpp/OctalToBinary.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#include <iostream>
using namespace std;

// Function to convert an
// Octal to Binary Number
string OctToBin(string octnum)
{
long int i = 0;

string binary = "";

while (octnum[i]) {
switch (octnum[i]) {
case '0':
binary += "000";
break;
case '1':
binary += "001";
break;
case '2':
binary += "010";
break;
case '3':
binary += "011";
break;
case '4':
binary += "100";
break;
case '5':
binary += "101";
break;
case '6':
binary += "110";
break;
case '7':
binary += "111";
break;
default:
cout << "\nInvalid Octal Digit "
<< octnum[i];
break;
}
i++;
}

return binary;
}

// Driver code
int main()
{
// Get the Hexadecimal number
string octnum = "345";

// Convert Octal to Binary
cout << "Equivalent Binary Value = "
<< OctToBin(octnum);

return 0;
}