0

please can you do a c++ program that converts octal to binary

octal to binary using any loop or switch statement

7th Feb 2019, 2:06 AM
Zelalem Tenaw Ztl
Zelalem Tenaw Ztl - avatar
1 Antwort
+ 1
#include <iostream> #include <math.h> using namespace std; int main() { int octal_numvalues[] = {0, 1, 10, 11, 100, 101, 110, 111}; long octal_num, tempoctal_num, binary_num, place; int rem; cout << "\n\n Convert any octal number to binary number:\n"; cout << "------------------------------------------------\n"; cout << " Input any octal number: "; cin>> octal_num; tempoctal_num = octal_num; binary_num = 0; place = 1; while (tempoctal_num != 0) { rem = (int)(tempoctal_num % 10); binary_num = octal_numvalues[rem] * place + binary_num; tempoctal_num /= 10; place *= 1000; } cout<<" The equivalent binary number: " << binary_num <<"\n"; } probably not but was worth a guess before crawling to bed at 2am, good luck :)
7th Feb 2019, 2:12 AM
peter
peter - avatar