Monday, July 13, 2009

Decimal to hexadecimal in c with coding?

it i s very easy


# include%26lt;stdio.h%26gt;


main()


{


int a;


printf('\n Enter no");


scanf("5d",%26amp;a);


printf('%x",a);


}

Decimal to hexadecimal in c with coding?
We are not here to provide you with your assignments, you can ask for help in coding syntax or algo, but we will not provide you with code, this will make you lazy
Reply:Look at the following programs





#include%26lt;stdio.h%26gt;





int main()


{


int hex_in = 0x0A0; //Initialize to a hex value





//To print in Decimal form use %d


printf("\nTo print in decimal form = %d",hex_in);





//To print in HEX form use %X


printf("\nTo print in HEX form = %X",hex_in);





return 0;


}








Note , Values in variables in any programs are in HEX format only , It just differs how you print them...


}
Reply:This program accepts a numeric command-line input in decimal form and outputs the value to the console in hexadecimal form.





#include %26lt;stdlib.h%26gt;


#include %26lt;stdio.h%26gt;


int main(int argc, char **argv)


{


   // first arg is the program's file name


   if (argc %26lt; 2)


      return 0;


   int i = atoi(argv[1]);


   printf("%x", i);


   return 0;


}





The first answer is partially correct in that radix (or number base) is an output-time representation feature, however, all numeric values are stored internally in *binary* form (not hexadecimal.)


No comments:

Post a Comment