Chemistry.report[1]
Chemistry.report[1]
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:
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.
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.
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.
Each function performs one specific task, making the code easy to manage.
4. Explaining the Flexibility of Using the Function in Main without Changing its Logic
(DRY Concept)
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.
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
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).
1 ÷ 16 = 0, remainder 1
Hexadecimal result: 1D8A
Implimentation in C :-
Final Code
Scalablity and Enhancement
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