Menu

Problem with 6 digit hexa decimal number!!!

aRTi S
2009-02-09
2012-09-26
  • aRTi S

    aRTi S - 2009-02-09

    I have this code i am trying to do :

    include<stdio.h>

    void main()
    {
    long int num1=0x5a,num2=0x30,num3=0x3a;
    long int result;
    result=(num10x10000)+(num20x100)+num3;
    printf(" number : %x",result);
    }

    but here the number shows only num3's value as output ...

    output : 3a

    i need to get the answer as 5a303a. There seems to be some memmory allocation error. But when i assigned values to an array :

    long int data[3][2]= { 0x52003a, 0x52003a, 0x743310, 0x740030, 0x22005a, 0x22005a };

    the values got stored successfully.

    Can u help me solve this problem?

    -Arti

     
    • cpns

      cpns - 2009-02-09

      The code worked correctly when I tried it in VC++ 2008, and I can see nothing immediately wrong with it. However I would suggest an alternative coding which will generally be more efficient (especially on processors without a hardware multiplier - I work in embedded systems so such things occur!):

      result =(num1 << 16) | (num2 << 8) | num3 ;

      On most processors bitwise logical operations execute faster that arithmetic operations.

      Note also that "long int" is a bit of an historical hangover. All compilers will accept just "long" as an integer type. 'long' is a type in its own right in modern compilers, rather than a qualifier for int. In fact that has been so in every compiler I have used since 1989.

      Clifford

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.