Hi,
i want to make a programme that convert any number system to any number system....means binary to hexa decimal....and many more can you give me some hint about this programme.....i think it is made by switch case....?????????
Printable View
Hi,
i want to make a programme that convert any number system to any number system....means binary to hexa decimal....and many more can you give me some hint about this programme.....i think it is made by switch case....?????????
Firstly, I want you to read this page.
Now that that's clarified, you need to decide how will you represent numbers with base higher that 16.
Secondly, "any number system to any number system" is pretty vague. Most ( if not all ) computers store numbers in binary. So you'll want to convert "any number system to binary" and "binary to any number system".
Hint: A lookup table is the fastest/easiest way to to it. For example:
Be warned, this code is untested.Code:void printBinary(unsigned int num)
{
char digits[2] = { '0', '1' };
char temp[65] = "";
char number[65] = "";
do
{
temp[0] = digits[num % 2];
temp[1] = '\0';
strcat(temp, number);
strcpy(number, temp);
num /= 2;
}while (num != 0);
printf("%s", number);
}