Convert Decimal to Hexadecimal Number

The decimal (base ten) numeral system has ten possible values (0,1,2,3,4,5,6,7,8, or 9) for each place-value. In contrast, the hexadecimal (base sixteen) numeral system has sixteen possible values, using the letters A, B, C, D, E, and F for the six place-values after 9.
To avoid confusion while using different numeral systems, the base of each individual number may be specified by writing it as a subscript of the number. For example, the decimal number 512 may be written as 51210 and read as "five hundred and twelve, base ten". The hexadecimal number 512 may be specified as "base sixteen" by writing it as 51216 (which is 1298 when converted to decimal).

program:
#include<stdio.h>
#include<conio.h>
#include<process.h>
void main()
{
Int x, y=30, z;
clrscr();
printf(“Enter the number:);
scanf(%d”, &x);
printf(“\n conversion of decimal to hexadecimal number\n”);
for(;;)
{
if(x= =0)
exit(1);
z=x%16;
x=x/16;
gotoxy(y--,5);
switch(z)
{
Case 10:
Printf(“A”);
Break;
Case 11:
Printf(%c”, „B?);
Break;
Case 12:
Printf(%c”, „C”);
Break;
Case 13:
Printf(“D”);
Break;
Case 14:
Printf(“E”);
Break;
Case 15:
Printf(“F”);
Default:
Printf(%d”, z);
}
}
getch();
}

Output:
Enter the number: 31
Conversion of decimal to Hexa decimal number
1F

0 comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...

Share

Twitter Delicious Facebook Digg Stumbleupon Favorites More