Thursday, March 1, 2018

  Program To Convert Octal Number System To Binary Number System.




/* C program to convert Octal number system to Binary number system */

#include <stdio.h>

int main()

{

int OCTALVALUES[] = {0, 1, 10, 11, 100, 101, 110, 111};

long long octal, tempOctal, binary, place;

int rem;

/* Input Octal number from user */

printf("Enter any Octal number: ");

scanf("%lld", &octal);

tempOctal = octal;

binary = 0;

place  = 1;

while(tempOctal > 0)

{                                                                         /* Extract the last digit of octal */

rem = tempOctal % 10;

/* Get the binary equivalent of octal digit

* add it to the binary variable  */

binary = (OCTALVALUES[rem] * place) + binary;

/* Remove the last octal digit */

tempOctal /= 10;

/* Increase the place value */

place *= 1000;

}

printf("Octal number = %lld\n", octal);

printf("Binary number = %lld", binary);

return 0;

}

Output
  Program To Convert Octal Number System To Binary Number System.

No comments:

Post a Comment

Life Articles And News:

Life Articles And News: