Hexa Decimal Addition in C

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sarchanakumar
    New Member
    • Nov 2006
    • 2

    Hexa Decimal Addition in C

    Hi friends, I want to write a program to add two hexa-decimal numbers. I know there is no way of direction addtion. My logic is, first convert two hexa-numbers into decimal after that we add and finally we have to convert the resultant decimal into hexadecimal. Is it right? Give your suggestion.
  • DeMan
    Top Contributor
    • Nov 2006
    • 1799

    #2
    I may be wrong, but I know hexadecimal numbers can be decalred 0x0f45 (for example, and stored as integers so I would imagine you can add them and do all sorts of things. I'm pretty sure when you are using printf to print to the screen, you can manipulate %d to display hexadecimal values

    Comment

    • horace1
      Recognized Expert Top Contributor
      • Nov 2006
      • 1510

      #3
      Originally posted by sarchanakumar
      Hi friends, I want to write a program to add two hexa-decimal numbers. I know there is no way of direction addtion. My logic is, first convert two hexa-numbers into decimal after that we add and finally we have to convert the resultant decimal into hexadecimal. Is it right? Give your suggestion.
      information is stored within the computer in binary and converted into decimal, octal or hex notation when we input and output numeric data. e.g. in to print a value in hex
      Code:
      	int i=0x02F4B;
      	printf("i in hex %#0x\n", i);
      and in C++
      Code:
      	int i=0x02F4B;
      	cout << "i in hex " << setiosflags(ios::showbase) << hex << i  << endl;
      when run both give
      i in hex 0x2f4b

      similar conversion is used to input data in hex

      Comment

      Working...