Sample – Program to convert 2-digit octal number into binary number and print it.

by Nideesh C on February 8, 2011 · 1 comment

in C++




#include <iostream.h>
#include <conio.h>
void octobin(int);

void main()
{
clrscr();
int a;
cout << “Enter a 2-digit octal number : “;
cin>>a;
octobin(a);
getch();
}
void octobin(int oct)
{
long bnum=0;
int A[6];
//Each octal digit is converted into 3 bits, 2 octal digits = 6 bits.
int a1,a2,quo,rem;
a2=oct/10;
a1=oct-a2*10;
for(int x=0;x<6;x++)
{
A[x]=0;
}
//Storing the remainders of the one’s octal digit in the array.
for (x=0;x<3;x++)
{
quo=a1/2;
rem=a1%2;
A[x]=rem;
a1=quo;
}
//Storing the remainders of the ten’s octal digit in the array.
for(x=3;x<6;x++)
{
quo=a2/2;
rem=a2%2;
A[x]=rem;
a2=quo;
}
//Obtaining the binary number from the remainders.
for(x=x-1;x>=0;x–)
{
bnum*=10;
bnum+=A[x];
}
cout << “The binary number for the octal number ” << oct << ” is ” << bnum << “.” << endl;
}

This program takes in a two-digit octal number a as a screen input from the user.
It then converts the octal number into a binary number and outputs it using the ‘cout’ command.

Not Satisfied ? Just search & get the result

Related Posts Plugin for WordPress, Blogger...
Be Sociable, Share!

Related posts:

  1. Sample – Program to enter an integer and print out its successor.
  2. Sample – Program to enter an integer and print its total value based on the formula ‘x – 1/3!x3 + 1/5!x5 – 1/7!x7 + 1/9!x9′.
  3. Sample – Program to count the number of words and characters in a sentence.
  4. Sample – Program to enter two integers and print the quotient and remainder.
  5. Sample – Program to enter an integer and output it in the reversed form.

{ 1 comment… read it below or add one }

1 Jone February 28, 2011 at 7:46 pm

including DivX, XviD, MOV, rm, rmvb, MPEG, VOB, DVD, WMV, AVI to MPEG-1, MPEG-2, MPEG-4, 3GP, FLV,F4V . It

Reply

Leave a Comment

Previous post:

Next post: