Introduction To Computing (GEL 103) Lab - Assignment 1 Deadline: 11 PM, 27.01.2016 Maximum Points: 10
Introduction To Computing (GEL 103) Lab - Assignment 1 Deadline: 11 PM, 27.01.2016 Maximum Points: 10
Lab Assignment 1
Deadline: 11 PM, 27.01.2016
Maximum Points: 10
Problem: Given two number bases b1, b2 and a number num, check whether num is a valid b1 base number. If yes, then convert the number num from number base b1 to number base b2 and print
the result, else print 0. You should consider the following four number bases:
1. Binary (base 2)
2. Octal (base 8)
3. Decimal (base 10)
4. Hexadecimal (base 16)
Write a C program to solve the above problem. Name the C file as base.c . To read the bases b1, b2
and number num, you need to use scanf. Please check the textbook or some on-line source for
details on the usage of scanf.
Test Cases:
:~$ b1 is: 2, b2 is: 10, num is: 10103
Output: 0, because 10103 is not a valid binary number.
:~$ b1 is: 2, b2 is: 10, num is: 1111
Output: 15
:~$ b1 is: 2, b2 is: 10, num is: 1001
Output: 9
:~$ b1 is: 10, b2 is: 2, num is: 4D2
Output: 0, because 4D2 is not a valid decimal number.
:~$ b1 is: 16, b2 is: 2, num is: 4D2
Output: 10011010010
:~$ b1 is: 8, b2 is: 10, num is: 109
Output: 0, because 109 is not a valid octal number.
:~$ b1 is: 8, b2 is: 10, num is: 107
Output: 71
Note: You should strictly follow the instructions given in the instruction file, which is available on
moodle.