Skip to content

Commit

Permalink
Update octal_to_binary.c
Browse files Browse the repository at this point in the history
  • Loading branch information
Suraj-Patro authored Oct 30, 2020
1 parent b282b95 commit f23987e
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions conversions/octal_to_binary.c
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/**
* @brief Octal to binay conversion by scanning user input
* @details
* The octalTobinary function take the octal number as long
* The octalTobinary function take the octal number as long
* return a long binary nuber after conversion
* @author [Vishnu P](https://github.com/vishnu0pothan)
*/
#include <stdio.h>
#include <math.h>
#include <stdio.h>

/**
* @brief Converet octal number to binary
Expand All @@ -21,32 +21,32 @@ long octalToBinary(int octalnum)
/* This loop converts octal number "octalnum" to the
* decimal number "decimalnum"
*/
while(octalnum != 0)
while (octalnum != 0)
{
decimalnum = decimalnum + (octalnum%10) * pow(8,i);
i++;
octalnum = octalnum / 10;
decimalnum = decimalnum + (octalnum % 10) * pow(8, i);
i++;
octalnum = octalnum / 10;
}

//i is re-initialized
// i is re-initialized
i = 1;

/* This loop converts the decimal number "decimalnum" to the binary
* number "binarynum"
*/
while (decimalnum != 0)
{
binarynum = binarynum + (long)(decimalnum % 2) * i;
decimalnum = decimalnum / 2;
i = i * 10;
binarynum = binarynum + (long)(decimalnum % 2) * i;
decimalnum = decimalnum / 2;
i = i * 10;
}

//Returning the binary number that we got from octal number
// Returning the binary number that we got from octal number
return binarynum;
}

/**
* @brief Main function
* @brief Main function
* @returns 0 on exit
*/
int main()
Expand All @@ -56,7 +56,7 @@ int main()
printf("Enter an octal number: ");
scanf("%d", &octalnum);

//Calling the function octaltoBinary
// Calling the function octaltoBinary
printf("Equivalent binary number is: %ld", octalToBinary(octalnum));
return 0;
}

0 comments on commit f23987e

Please sign in to comment.