![]() |
VOOZH | about |
Number system conversion is a fundamental concept in computer science and programming. It involves changing the representation of a number from one base to another, such as converting a decimal number to binary or a hexadecimal number to binary.
In this article, we will create a console program in the C language to perform various number system conversions. Our program will be capable of conversion between the following number systems:
Before we look into the C program, let's discuss some of the commonly used number systems:
We define functions for decimal-to-binary, binary-to-decimal, and other mentioned conversions. These functions implement the standard method for the respective conversions.
In the main function, we display a menu of conversion options and ask the user to select one. Depending on the user's choice, we take input and call the corresponding conversion function. The conversion functions perform the conversion and display the result.
1. Decimal to Binary
Menu:
1. Decimal to Binary
2. Binary to Decimal
3. Decimal to Octal
4. Octal to Decimal
5. Hexadecimal to Binary
6. Binary to Hexadecimal
7. Exit
Enter your choice: 1
Enter a decimal number: 128
Decimal to Binary: 100000002. Binary to Decimal
Menu:
1. Decimal to Binary
2. Binary to Decimal
3. Decimal to Octal
4. Octal to Decimal
5. Hexadecimal to Binary
6. Binary to Hexadecimal
7. Exit
Enter your choice: 2
Enter a binary number: 10000000
Binary to Decimal: 1283. Decimal to Octal
Menu:
1. Decimal to Binary
2. Binary to Decimal
3. Decimal to Octal
4. Octal to Decimal
5. Hexadecimal to Binary
6. Binary to Hexadecimal
7. Exit
Enter your choice: 3
Enter a decimal number: 100
Decimal to Octal: 1444. Octal to Decimal
Menu:
1. Decimal to Binary
2. Binary to Decimal
3. Decimal to Octal
4. Octal to Decimal
5. Hexadecimal to Binary
6. Binary to Hexadecimal
7. Exit
Enter your choice: 4
Enter an octal number: 144
Octal to Decimal: 1005. Hexadecimal to Binary
Menu:
1. Decimal to Binary
2. Binary to Decimal
3. Decimal to Octal
4. Octal to Decimal
5. Hexadecimal to Binary
6. Binary to Hexadecimal
7. Exit
Enter your choice: 5
Enter a hexadecimal number: a10
Hexadecimal to Binary: 1010000100006. Binary to Hexadecimal
Menu:
1. Decimal to Binary
2. Binary to Decimal
3. Decimal to Octal
4. Octal to Decimal
5. Hexadecimal to Binary
6. Binary to Hexadecimal
7. Exit
Enter your choice: 6
Enter a binary number: 101000010000
Binary to Hexadecimal: A10To learn the concept behind the conversion, you can refer to these articles: