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
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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
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