Program to convert Octal to Binary C++

Programming Logic:

To convert or change the octal number to binary number replace the each octal digits by a binary number using octal to binary chart.

octal to binary c++

 

For example take 25: Binary of 2 is 010 and Binary of 5 is 101.

Therefore binary of octal 25 is: 010101

Program to convert Octal to Binary C++:

#include<iostream>
using namespace std;

#define MAX 1000

int main()
{

    char octalNumber[MAX];
    long int i=0;

    cout<<"Enter any octal number: ";
    cin>>octalNumber;

    cout<<"Equivalent binary value: ";
    while(octalNumber[i])
    {
        switch(octalNumber[i])
    {
             case '0': cout<<"000";
             break;
             case '1': cout<<"001";
         break;
             case '2': cout<<"010";
         break;
             case '3': cout<<"011";
         break;
             case '4': cout<<"100";
         break;
             case '5': cout<<"101";
         break;
             case '6': cout<<"110";
         break;
             case '7': cout<<"111";
         break;
             default:  cout<<"nInvalid octal digit "<<octalNumber[i];
         return 0;
        }
        i++;
    }

    return 0;
}

 

OUTPUT:

octal to binary c++

Program to convert Decimal to Hexadecimal C++

Decimal Number System:  It is base 10 number system which uses the digits from 0 to 9. Hexadecimal Number System: It is base 16 number system which uses the digits from 0 to 9 and A, B, C, D, E, F. Logic to Convert Decimal to Hexadecimal C++: Divide the original decimal number by 16. … Read more

Program to Display Size of various Data Types in C++

Write a Program to Display Size of various Data Types in C++ PROGRAM: #include<iostream> using namespace std; int main() { int x=25; cout<<"sizeof(char)tt"; cout<<sizeof(char)<<endl; cout<<"sizeof(signed char)t"; cout<<sizeof(signed char)<<endl; cout<<"sizeof(unsigned char)t"; cout<<sizeof(unsigned char)<<endl; cout<<"sizeof(int)tt"; cout<<sizeof(int)<<endl; cout<<"sizeof(signed int)t"; cout<<sizeof(signed int)<<endl; cout<<"sizeof(unsigned int)t"; cout<<sizeof(unsigned int)<<endl; cout<<"sizeof(short)tt"; cout<<sizeof(short)<<endl; cout<<"sizeof(signed short)t"; cout<<sizeof(signed short)<<endl; cout<<"sizeof(unsigned short)t"; cout<<sizeof(unsigned short)<<endl; cout<<"sizeof(short int)t"; cout<<sizeof(short int)<<endl; … Read more

Program to find the Number of Vowels, Consonants, Digits and White Space in a String

PROGRAM:

#include<iostream>
#include<cstring>
using namespace std;

int main()
{
    char line[150];
    int i,v,c,ch,d,s,o; o=v=c=ch=d=s=0;
    cout << "Enter a line of string: " << endl;
    cin.getline(line, 150);
    for(i=0;line[i]!='';++i)
    {
        if(line[i]=='a'
        || line[i]=='e'
        || line[i]=='i'
        || line[i]=='o'
        || line[i]=='u'
        || line[i]=='A'
        || line[i]=='E'
        || line[i]=='I'
        || line[i]=='O'
        || line[i]=='U')
            ++v;
        else if((line[i]>='a'&& line[i]<='z')
               || (line[i]>='A'&& line[i]<='Z'))
                ++c;
        else if(line[i]>='0'&&c<='9')
                ++d;
        else if (line[i]==' ')
                ++s;
    }
    cout << " Vowels: " << v << endl;
    cout << " Consonants: " << c << endl;
    cout << " Digits: " << d << endl;
    cout << " White Spaces: " << d << endl;
    return 0;
}

 

OUTPUT:

find number of vowels consonants digits and white space in a string