Uploaded by kalkulatingkalkulator

Decimal to Binary Conversion Coding Assignment

advertisement
CE 465 Numerical Methods in Civil Engineering
Coding Assignment 1: Decimal to Binary Conversion
Marks: 10
Instructions:
•
•
•
•
•
Plagiarism will be checked for your code. You must write your own code. A student found
copying in an assignment is given a zero in the assignment, and a penalty will be given as
per institute norms.
You can use any programming language to write your code.
The deadline for submission is 11th February 2025, 11.59 PM. Late submissions are not
allowed.
While submitting, you need to upload the following documents:
• An original code file.
• An output file (format: .txt) from the above code.
Contact Aayush Kumar Verma (ayush.verma@iitb.ac.in, Room no. 035, Department of
Civil Engineering) for clarifications.
Question:
Write a program to convert a given decimal number into its binary representation without using
the built-in functions. Your program should handle the following requirements:
•
•
•
•
The binary representation should be returned as a number.
It should handle edge cases where the input is negative or zero.
If the input is a negative integer, you can use methods like 2’s compliment (8 digits). Refer
to the attached PDF for more details on this method.
The code should be worked for fraction numbers (e.g. 0.625 and 13.6).
You need to provide outputs for the following numbers using your code: 5, -45, 0.23, 0,
2.56.
You can provide your output in the following way:
Decimal Input: 5, Binary Output: 101
Decimal Input: -45.0, Binary Output: 11010011
Decimal Input: 0.23, Binary Output: 0.0011101011
Decimal Input: 0, Binary Output: 0
Decimal Input: 2.56, Binary Output: 10.1000111101
Download