0% found this document useful (0 votes)
17 views16 pages

Chemistry.report[1]

The document presents a project report from a group of students at Thakur College of Engineering & Technology, focusing on developing a C program that converts decimal numbers into binary, octal, and hexadecimal formats. It outlines the theoretical background of number systems, the methodology for conversion, and the implementation details, emphasizing modular programming principles. The project aims to enhance understanding of number system conversions and provides a foundation for future enhancements and scalability in programming.

Uploaded by

tiwari.priya2206
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views16 pages

Chemistry.report[1]

The document presents a project report from a group of students at Thakur College of Engineering & Technology, focusing on developing a C program that converts decimal numbers into binary, octal, and hexadecimal formats. It outlines the theoretical background of number systems, the methodology for conversion, and the implementation details, emphasizing modular programming principles. The project aims to enhance understanding of number system conversions and provides a foundation for future enhancements and scalability in programming.

Uploaded by

tiwari.priya2206
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16

Department of Computer Science and Engineering (CyberSecurity) Thakur

College of Engineering & Technology, Mumbai-India

A C PROGRAM TO CONVERT DECIMAL NUMBER TO


IT’S BINARY,OCTAL, AND HEXADECIMAL
BY GROUP NO.6 CSE
1.Rudra Pratap Singh (53) 7.Darsh Vyas (59)
2.Ziyan Solanki (54) 8.Ankit Yadav (60)
3.Harshwardhan Tiwari (55) 9.Krish Yadav (61)
4.Priya Tiwari (56) 10.Nikita Yadav (62)
5.Rudra Umatiya (57) 11.Pooja Yadav (63)
6.Sagar Vishwakarma (58) 12.Utsav Yadav (64)

An Innovative Examination (IE) Report Submitted for the


Subject of
PROGRAMMING AND PROBLEM SOLVING
Under the Guidance of
Ms.Antima Shah
Assistant Professor
A.Y.2024-25
ABSTRACT
The objective of this project is to develop a C program that converts
a given decimal number into its binary, octal, and hexadecimal
representations using functions. The program will take a decimal
number as input from the user and utilize separate functions for each
conversion process. The implementation will demonstrate
fundamental C programming concepts such as function calls, loops,
and conditional statements. This project aims to enhance the
understanding of number system conversions and function-based
programming in C. The final output will display the converted values
in a structured format, making it a practical tool for learning and
computational applications.
INTRODUCTION:
Number systems play a crucial role in computer science and digital electronics. The
decimal number system (base-10) is commonly used by humans, while computers
operate using binary (base-2), octal (base-8), and hexadecimal (base-16) number
systems. Converting numbers between these representations is essential for
various computational tasks, including programming, data encoding, and low-level
hardware operations.This project focuses on developing a C program that converts
a given decimal number into its binary, octal, and hexadecimal equivalents using
functions. By employing modular programming principles, the implementation
enhances code reusability, readability, and efficiency. Each conversion process is
handled by a dedicated function, demonstrating structured programming in C.

The project not only reinforces fundamental programming concepts such as


function calls, loops, and conditional statements but also provides a deeper
understanding of number system conversions. The developed program serves as a
useful tool for students, programmers, and engineers dealing with numerical data
representation in different bases.

THEORETICAL BACKGROUND
Number systems are the foundation of computing and digital electronics. A number
system defines how numbers are represented and processed in different contexts.
The most commonly used number systems include:
1. Decimal (Base-10): The decimal system consists of ten digits (0-9) and
is the standard system used in daily life. Each digit's position
represents a power of 10.
2. Binary (Base-2): The binary system is fundamental in computing,
consisting of only two digits: 0 and 1. Every binary digit (bit)
represents a power of 2, making it the primary language of digital
circuits and processors.
3. Octal (Base-8): The octal system uses eight digits (0-7), with each digit
representing a power of 8. Octal is often used as a shorthand for
binary in computing, as three binary digits correspond to one octal
digit.
4. Hexadecimal (Base-16): The hexadecimal system extends the decimal
system by using 16 symbols: digits (0-9) and letters (A-F) representing
values 10-15. Hexadecimal is widely used in programming, memory
addressing, and color representation in digital graphics.
Number System Conversions
Converting a decimal number into binary, octal, or hexadecimal involves dividing
the number by the target base and recording the remainders. The process follows
these steps:

1. Division Method:

⚬ Divide the decimal number by the base (2, 8, or 16).

⚬ Record the remainder as the least significant digit.

⚬ Repeat the process with the quotient until it reaches zero.

⚬ The final converted number is obtained by reading the


remainders in reverse order.
2. Mapping for Hexadecimal Conversion:

⚬ Since hexadecimal includes digits beyond 9, values 10-15 are


mapped to 'A' to 'F'.
Function-Based Implementation in C:
In C programming, functions are used to modularize the conversion process. Each
number system conversion is implemented as a separate function, making the
program structured, reusable, and easier to debug. Functions help in breaking
down the problem into smaller, manageable parts, ensuring an efficient and
systematic approach to solving the problem.
This project applies these theoretical concepts to develop a program that efficiently
converts a decimal number into its binary, octal, and hexadecimal equivalents,
demonstrating the practical application of number system conversions in
programming.

APPROACH FOR SOLUTION


To develop an efficient solution for converting a decimal number into binary, octal,
and hexadecimal, a structured approach is followed. The methodology is broken
down into four key steps:

1. Understanding the Problem

The primary objective is to take a decimal number as input and convert it into its
equivalent representations in different number systems—binary, octal, and
hexadecimal. This requires a clear understanding of number system conversions
and how computers process different bases. The solution should be function-
based, ensuring modularity, reusability, and simplicity in implementation.

2. Method to Convert Manually

Before implementing the solution in C, it is essential to understand how the


conversion works manually. The decimal-to-binary, decimal-to-octal, and decimal-
to-hexadecimal conversions follow a similar process:
Repeated division by the target base (2 for binary, 8 for octal, 16 for hexadecimal).

Recording the remainder at each step.

Reading the remainders in reverse order to obtain the final result.

For example, to convert 25 into binary:

25 ÷ 2 = 12, remainder = 1

12 ÷ 2 = 6, remainder = 0

6 ÷ 2 = 3, remainder = 0

3 ÷ 2 = 1, remainder = 1

1 ÷ 2 = 0, remainder = 1

Reading from bottom to top, 25 in binary is 11001. The same process applies to
octal and hexadecimal, with hexadecimal requiring an additional step of mapping
values 10-15 to A-F.

3. Creating a Function with Decimal Number as Argument and Applying the


Method in C

To keep the program modular, separate functions are created for each conversion.
These functions take a decimal number as an argument and apply the division-
remainder method to generate the required number format.

Using functions allows a structured approach:

Each function performs one specific task, making the code easy to manage.

The logic for conversion is reusable without modifications.

Functions improve readability and debugging.


For example, a function convertToBinary(int num) will process the decimal number
and print its binary equivalent. Similarly, functions for octal and hexadecimal
conversion will follow the same logic but with different base values.

4. Explaining the Flexibility of Using the Function in Main without Changing its Logic
(DRY Concept)

The DRY (Don't Repeat Yourself) principle is a fundamental programming practice


that avoids redundant code. Instead of writing the same conversion logic multiple
times, a well-designed function can be used anywhere in the program without
altering its internal logic.

For instance, in a menu-driven application, the user can choose an option to


convert a decimal number into the desired format:

Press 1 for Binary conversion

Press 2 for Octal conversion

Press 3 for Hexadecimal conversion

Press 4 to Exit

In this case, a single function for each conversion can be called dynamically based
on user input, rather than rewriting conversion logic repeatedly. This improves
efficiency and makes the program scalable.
BOILERPLATE CODE
The boilerplate code serves as the foundational structure of the program, ensuring
proper input handling and execution flow. It includes:
Header File Inclusion:
The #include <stdio.h> directive is used to include the standard input-output
library, which provides functions like printf() and scanf() for user interaction.

Main Function (main())


The main() function acts as the entry point of the program.
A variable decimal is declared to store the user-inputted decimal number.
The program prompts the user to enter a decimal number, which is then read using
scanf().

The function call section (currently a placeholder) will later be used to invoke
conversion functions for binary, octal, and hexadecimal representations.
The program returns 0 to indicate successful execution.
Decimal to Binary Conversion
1. Binary Representation Format
Binary is a base-2 number system that uses only two digits:
0 and 1. Each digit represents a power of 2, making it the
fundamental numbering system for computers.
2. Manual Conversion Method
To convert a decimal number to binary:
Divide the decimal number by 2.
Record the remainder (this forms the binary digits).
Repeat the process until the quotient becomes 0.
Read the remainders in reverse order to get the binary
equivalent.
Example: Convert 13 to binary
13 ÷ 2 = 6, remainder 1
6 ÷ 2 = 3, remainder 0
3 ÷ 2 = 1, remainder 1
1 ÷ 2 = 0, remainder 1
Binary result: 1101
Implimentation in C

o Enhanced Cycle Life: Supercapacitors with phase-engineered materials


retain 90% capacitance after 10,000 cycles.
Decimal to Octal Conversion
1. Octal Representation Format
Octal is a base-8 number system that uses digits 0 to 7. Each digit represents a
power of 8, making it useful in computing as a shorthand for binary (since 8 is a
power of 2).

2. Manual Conversion Method


To convert a decimal number to octal:
Divide the decimal number by 8.
Record the remainder (this forms the octal digits).
Repeat the process until the quotient becomes 0.

Read the remainders in reverse order to get the octal equivalent.


Example: Convert 78 to octal
78 ÷ 8 = 9, remainder 6
9 ÷ 8 = 1, remainder 1
1 ÷ 8 = 0, remainder 1
Octal result: 116

Implimentation in C
Decimal to Hexadecimal Conversion
1. Hexadecimal Representation Format
Hexadecimal (base-16) uses digits 0-9 and letters A-F to represent values from 0
to 15.
Example: 10 in decimal is A in hexadecimal, 15 is F, 16 is 10, and so on.
It is commonly used in computing, especially for memory addresses and color
codes.
2. Manual Conversion Method
To convert a decimal number to hexadecimal:
Divide the decimal number by 16.
Record the remainder (0-9 → same digit, 10-15 → A-F).

Repeat the process until the quotient becomes 0.


Read the remainders in reverse order to get the final hexadecimal result.
Example: Convert 7562 to hexadecimal
7562 ÷ 16 = 472, remainder 10 (A)
472 ÷ 16 = 29, remainder 8
29 ÷ 16 = 1, remainder 13 (D)

1 ÷ 16 = 0, remainder 1
Hexadecimal result: 1D8A
Implimentation in C :-
Final Code
Scalablity and Enhancement

1. The current implementation provides a structured approach to number


system conversion, making it easy to read and maintain. However, there are
several ways to enhance and scale the program further:
2. Returning Values Instead of Modifying Buffers
3. Currently, the functions modify an external buffer, which requires the caller
to allocate memory beforehand.
4. A more flexible approach would be for each function to return a dynamically
allocated string, allowing the calling function to store, print, or process it
later.
5. This would improve code reusability and allow post-processing of the
converted values before displaying them.
6. Menu-Driven Program for Better Usability
7. Instead of manually running each function separately, we can create a menu-
driven program where users can choose the conversion type (binary, octal,
hexadecimal) interactively.
8. This approach makes the program user-friendly and scalable, allowing easy
integration of additional conversion types in the future.
9. The menu-driven system can also provide error handling and input
validation, making it robust for practical use.
10. Extending to Other Number Systems
11. The current approach can be extended to support other bases (base-3, base-
5, base-12, etc.), making the program more versatile.
12. By generalizing the conversion function, we can allow users to input any
desired base instead of restricting them to binary, octal, or hexadecimal.
13. These enhancements ensure that the program remains scalable, reusable,
and adaptable for various applications
CONCULSION
This project successfully implements a modular and efficient approach to
converting decimal numbers into binary, octal, and hexadecimal representations
using functions in C. By following a structured methodology, we ensured that each
function is reusable, easy to understand, and adaptable for future enhancements.
The implementation highlights key programming concepts such as iterative
division, string manipulation, and modular design, reinforcing the importance of
structured problem-solving in software development. Additionally, the potential for
scalability, including a menu-driven interface and support for other number
systems, makes this project a strong foundation for further improvements.
Overall, this project not only demonstrates the practical application of number
system conversions but also emphasizes clean coding practices, making it a
valuable learning experience in function-based programming in C.
ACKNOWLEDGEMENT
We would like to express our sincere gratitude to all those who have supported and
contributed to the completion of this report on smart materials. First and foremost,
we would like to thank our professor Ms.Antima Shah for their invaluable guidance,
insight, and encouragement throughout the research process. Their expertise and
feedback have been instrumental in shaping the direction of this report. And, also
thank TCET MUMBAI for giving us the opportunity to use their resources and work
in challenging environment.
REFERENCES

https://www.geeksforgeeks.org/generating-random-numbers-in-java/
https://stackoverflow.com/questions/66570194/how-to-check-the-data-type-of-a-
user-inp ut-
java#:~:text=nextInt()%20would%20do%20that,You%20can%20also%20use%20Inte
ger.
https://www.tutorialspoint.com/cprogramming

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy