0% found this document useful (0 votes)
9 views22 pages

Report Format Mini Project CSF101

Uploaded by

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

Report Format Mini Project CSF101

Uploaded by

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

PROJECT REPORT (CSF101)

A report submitted in partial fulfilment of the requirement for the course

PROGRAMMING FOR PROBLEM SOLVING


Part of the degree of

BACHELOR OF COMPUTER SCIENCE AND ENGINEERING

Submitted to
Dr. Madhu Sharma
Assistant Professor
Submitted by: Tushar Mavi
SAP ID - 1000024679 Section - J
Group No - 1

SCHOOL OF COMPUTING
DIT UNIVERSITY, DEHRADUN
(State Private University through State Legislature Act No. 10 of 2013 of Uttarakhand and approved by UGC)

Mussoorie Diversion Road, Dehradun, Uttarakhand - 248009, India.


November, 2024
CANDIDATES DECLARATION

I hereby certify that the work, which is being presented in the Report, entitled “Number Base
Converter”, in partial fulfilment of the requirement as part of the course Programming for
Problem Solving of the Degree of Bachelor of Computer Science and Engineering and
submitted to the DIT University is an authentic record of my work carried out during the
period 12/10/2024 to 15/11/2024 under the guidance of Dr. Madhu Sharma.

Date: 9-11-2024
Signature of the Candidate

Student Name – Tushar Mavi SAP ID - 1000024679 Branch – B.Tech(IT)


TABLE OF CONTENT
CHAPTER PAGE No.

Student Name – Tushar Mavi SAP ID - 1000024679 Branch – B.Tech(IT)


Rules for Fonts in chapters
1. Chapter heading 16, Times new Roman
2. Sub Headings 14
3. Text 12, Times new roman
4. Each figure caption – 10, times new roman
5. Line spacing 1.5

Student Name – Tushar Mavi SAP ID - 1000024679 Branch – B.Tech(IT)


Introduction

Briefly describe the problem domain with suitable examples.

 Decimal (Base 10): The decimal system is the most commonly


used number system, consisting of digits 0 to 9. Each digit’s
position represents a power of 10. For example, the decimal
number 123 is represented as (1 * 102) + (2 * 101) + (3 * 100).

 Binary (Base 2): The binary system consists of only two digits, 0
and 1. This system is mostly used as in machines where each
digit’s position represents a power of 2. For example, the binary
number 1101 is represented as (1 * 23) + (1 * 22) + (0 * 21) + (1 *
20).

 Octal (Base 8): The octal system consists of digits 0 to 7. Each


digit’s position represents a power of 8. For example, the octal
number 53 is represented as (5 * 81) + (3 * 80).

 Hexadecimal (Base 16): The hexadecimal system uses digits 0 to 9


and letters A to F (or a to f) to represent values from 0 to 15. Each
digit’s position represents a power of 16. For example, the
hexadecimal number 1A3 is represented as (1 * 162) + (10 * 161)
+ (3 * 160)

Student Name – Tushar Mavi SAP ID - 1000024679 Branch – B.Tech(IT)


Project Description
Purpose: Number Base Converter

Problem statement:

#include <stdio.h>
#include <stdlib.h>

void decimalToBinary(int n) {
if (n == 0) {
printf("0");
return;
}
int binary[32]; // Array to store binary number
int index = 0;

Student Name – Tushar Mavi SAP ID - 1000024679 Branch – B.Tech(IT)


while (n > 0) {
binary[index++] = n % 2; // Store remainder
n /= 2; // Divide by 2
}

// Print in reverse order


for (int i = index - 1; i >= 0; i--) {
printf("%d", binary[i]);
}
}

void decimalToOctal(int n) {
if (n == 0) {
printf("0");
return;

}
int octal[32]; // Array to store octal number
int index = 0;

while (n > 0) {
octal[index++] = n % 8; // Store remainder
n /= 8; // Divide by 8

Student Name – Tushar Mavi SAP ID - 1000024679 Branch – B.Tech(IT)


}

// Print in reverse order


for (int i = index - 1; i >= 0; i--) {
printf("%d", octal[i]);
}
}

void decimalToHexadecimal(int n) {
if (n == 0) {
printf("0");
return;
}
char hexadecimal[32]; // Array to store hexadecimal number
int index = 0;

while (n > 0) {
int remainder = n % 16;
if (remainder < 10) {
hexadecimal[index++] = remainder + '0'; // Convert to char
} else {
hexadecimal[index++] = remainder - 10 + 'A'; // Convert to char
}

Student Name – Tushar Mavi SAP ID - 1000024679 Branch – B.Tech(IT)


n /= 16; // Divide by 16
}

// Print in reverse order


for (int i = index - 1; i >= 0; i--) {
printf("%c", hexadecimal[i]);
}
}

int main() {
int number, baseFrom, baseTo;

printf("Enter the number: ");


scanf("%d", &number);
printf("Enter the base of the number (2 for binary, 8 for octal, 10 for
decimal, 16 for hexadecimal): ");
scanf("%d", &baseFrom);
printf("Enter the base to convert to (2 for binary, 8 for octal, 10 for
decimal, 16 for hexadecimal): ");
scanf("%d", &baseTo);

// Convert input number to decimal


int decimalNumber = 0;

Student Name – Tushar Mavi SAP ID - 1000024679 Branch – B.Tech(IT)


int multiplier = 1;
int temp = number;

// Convert from specified base to decimal


while (temp > 0) {
decimalNumber += (temp % 10) * multiplier;
temp /= 10;
multiplier *= baseFrom;
}

// Print the result in the desired base


printf("Converted number: ");
if (baseTo == 2) {
decimalToBinary(decimalNumber);
} else if (baseTo == 8) {
decimalToOctal(decimalNumber);
} else if (baseTo == 10) {
printf("%d", decimalNumber);
} else if (baseTo == 16) {
decimalToHexadecimal(decimalNumber);
} else {
printf("Invalid base.");
}

Student Name – Tushar Mavi SAP ID - 1000024679 Branch – B.Tech(IT)


printf("\n");
return 0;
}

System Requirements:

 Hardware requirements
 Processor : Intel Core i3
 Ram : 8 GB
 Disk space : 256 GB

 software requirements
 C
 Mingw
 Operating System : Windows 11

Student Name – Tushar Mavi SAP ID - 1000024679 Branch – B.Tech(IT)


Methods and Implementation

 First discuss each module of project

 Write pseudocode/flowchart of each module/function

 Discuss about data structure used to solve this problem


Student Name – Tushar Mavi SAP ID - 1000024679 Branch – B.Tech(IT)
 Write the c code for each module
 Screen shots of codes and outputs

 Result analysis

Analyzing the results of a number base converter in C involves


understanding how to convert numbers between different bases and then
verifying that the conversion is accurate. Here's a simple overview of
how to implement a number base converter, along with an explanation
of the results.

### Basic Steps for a Number Base Converter

Student Name – Tushar Mavi SAP ID - 1000024679 Branch – B.Tech(IT)


1. **Input**: Accept a number in a given base and the target base to
convert to.
2. **Conversion Logic**:
- Convert the input number from its original base to decimal (base 10).
- Convert the decimal number to the desired target base.
3. **Output**: Display the converted number.

### Example Code

Here's a simple implementation of a number base converter in C:

```c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

// Function to convert a number from any base to decimal


int toDecimal(char *number, int base) {
int len = strlen(number);
int power = 1; // base^0
int decimalValue = 0;

Student Name – Tushar Mavi SAP ID - 1000024679 Branch – B.Tech(IT)


// Convert the number from the given base to decimal
for (int i = len - 1; i >= 0; i--) {
if (number[i] >= '0' && number[i] <= '9') {
decimalValue += (number[i] - '0') * power;
} else if (number[i] >= 'A' && number[i] <= 'F') {
decimalValue += (number[i] - 'A' + 10) * power;
}
power *= base;
}

return decimalValue;
}

// Function to convert a decimal number to a specified base


void fromDecimal(int decimal, int base, char *result) {
int index = 0;
while (decimal > 0) {
int remainder = decimal % base;
if (remainder < 10) {
result[index++] = remainder + '0';
} else {
result[index++] = (remainder - 10) + 'A';

Student Name – Tushar Mavi SAP ID - 1000024679 Branch – B.Tech(IT)


}
decimal /= base;
}
result[index] = '\0';

// Reverse the string to get the correct representation


for (int i = 0; i < index / 2; i++) {
char temp = result[i];
result[i] = result[index - i - 1];
result[index - i - 1] = temp;
}
}

// Main function
int main() {
char number[20];
int base, targetBase;
char result[20];

printf("Enter a number: ");


scanf("%s", number);
printf("Enter the base of the number (2-16): ");
scanf("%d", &base);

Student Name – Tushar Mavi SAP ID - 1000024679 Branch – B.Tech(IT)


printf("Enter the target base (2-16): ");
scanf("%d", &targetBase);

int decimalValue = toDecimal(number, base);


fromDecimal(decimalValue, targetBase, result);

printf("The number %s in base %d is %s in base %d\n", number, base,


result, targetBase);

return 0;
}
```

### Explanation of the Code

1. **toDecimal Function**:
- This function takes a string representation of a number and its base.
- It calculates the decimal value by iterating through each digit,
converting it according to its position, and summing the results.

2. **fromDecimal Function**:
- This function converts a decimal number to the specified target base.

Student Name – Tushar Mavi SAP ID - 1000024679 Branch – B.Tech(IT)


- It uses the modulus operator to get the remainder (which corresponds
to the next digit in the target base), appending the digits to a result
string.
- Finally, it reverses the string to present the digits in the correct order.

3. **Main Function**:
- It prompts the user for input, calls the conversion functions, and
prints the result.

### Result Analysis

When you run the program, you can test various inputs and bases. For
example:

- Inputting `1010` in base `2` and converting to base `10` should yield
`10`.
- Inputting `A` in base `16` and converting to base `10` should yield
`10`.

### Verifying Results

To analyze the correctness of the results, you can compare them with
manual conversions or use known values.

Student Name – Tushar Mavi SAP ID - 1000024679 Branch – B.Tech(IT)


- **Manual Calculation**: For each conversion, manually convert the
number using the definitions of base values to ensure accuracy.
- **Edge Cases**: Test with edge cases like the smallest (0) and largest
numbers representable in a given base.

By systematically analyzing the results and ensuring correctness, you


can confirm that the number base converter works as expected.

Student Name – Tushar Mavi SAP ID - 1000024679 Branch – B.Tech(IT)


Conclusion
Discuss the summary of the project done

Thus, in closure; number base converters are very crucial for converting numbers
from one place value system like Binary to another such as Decimal and octal or
hexadecimal. In computer science, engineering or in maths it is very important to
understand how these conversions work.
Key takeaways include:
1. Considering Bases: A number system has a base (referred to as “B” ) which is
the power of it. Binary is for base 2, decimal is for base 10, octal are Base-8 and
hexadecimal ones are those who have the Base of16. as in:
2. Conversion methods: Numerous techniques for conversion exist, this will11
Direct Conversion: converting between bases by complex mathematic calculations.
Place Value Method: To Know the value of each digit depending on its position.
Algorithmic Methods: Process involves applying a conversion algorithm.
3. Applications- It is used in programming, digital electronics and data
representation which help us to know how computers process numbers.

Student Name – Tushar Mavi SAP ID - 1000024679 Branch – B.Tech(IT)


If you can master number base conversions, it will be great help when solving
problems and getting a grasp of what is going on under the hood in all things
computational.

Bibliography

This can include reference of books, web links, and software used
Books

1. Bishop, J. (2019). The Complete Manual of Binary and Hexadecimal


Number Systems in Digital Computer System Cambridge University
Press.
2. Patterson, D. A., and Hennessy, J. L.. 2017 Computer Organization and
Design: The Hardware/software Interface Morgan Kaufmann.
3. Morley, S., and Parker, C. (2016). Computer Science: A Structured
Programming Approach Using C++ Cengage Learning.

Online Resources
1. Wolfram Alpha. "Number Base Conversion." Retrieved from
Wolfram Alpha.

Student Name – Tushar Mavi SAP ID - 1000024679 Branch – B.Tech(IT)


2. GeeksforGeeks. "Number Systems and Their Conversions."
Retrieved from GeeksforGeeks.
3. Khan Academy. "Binary and Decimal Number Conversion."
Retrieved from Khan Academy.

Student Name – Tushar Mavi SAP ID - 1000024679 Branch – B.Tech(IT)

You might also like