This is a Number Base Conversion Program written in C. It is designed to assist novice C programmers in understanding and implementing basic number base conversions of numeral system. This program allows users to perform the following conversions:

  1. Decimal to Binary: Converts a decimal number to its binary equivalent.
  2. Decimal to Octal: Converts a decimal number to its octal equivalent.
  3. Octal to Decimal: Converts an octal number to its decimal equivalent.
  4. Octal to Binary: Converts an octal number to its binary equivalent.
  5. Binary to Decimal: Converts a binary number to its decimal equivalent.
  6. Binary to Octal: Converts a binary number to its octal equivalent.

New C programmers can use this program as a reference to grasp fundamental concepts of number base conversions and modular programming in the C language.

This program utilizes several features of the C programming language to achieve its functionality. Here are some of the key C features used in the program. It also uses functions from the math.h library for mathematical operations.

  1. Functions: The program uses functions to encapsulate specific conversion tasks. Functions such as binaryToDecimal, decimalToBinary, octalToDecimal, decimalToOctal, octalToBinary, and binaryToOctal are defined to perform individual conversion operations. This modular approach enhances code readability and maintainability.
  2. Switch Statement: The program employs a switch statement to provide a menu-driven interface. The user can select the desired conversion option by entering a corresponding menu number. The switch statement directs the program flow based on the user’s choice.
  3. Loops (while, for): The program utilizes while loops in the decimalToBinary, decimalToOctal, octalToBinary, and binaryToOctal functions for iterative processes. Additionally, a for loop is used in the binaryToDecimal and octalToDecimal functions to iterate through the input string.
  4. Arrays (Strings): The program makes use of character arrays (strings) to store binary, octal, and decimal representations. Arrays like input, binaryOutput, octalOutput, binaryOutputOctal, and octalOutputBinary are employed to store user input and conversion results.
  5. Standard Input/Output: The program relies on standard input/output functions (printf and scanf) for user interaction. It prompts users for input and displays conversion results through the console.
  6. Math Library (pow function): The program uses the pow function from the math library to perform power calculations. This is employed in the binaryToDecimal and octalToDecimal functions to calculate the decimal equivalent of binary and octal numbers.
  7. Conditional Statements: The program includes conditional statements (if) to check for specific conditions, such as determining whether a binary digit is ‘1’ in the binaryToDecimal function.

Number Base Conversion Program in C Language