Hello everyone,
Currently I'm doing an embedded project with byte programming with C. The following is the program:
Code C - [expand] |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
| #include <stdio.h>
void main ()
{
long velocity;
union
{
int NUMvelo;
int byte[2];
} CURRENTvelo;
CURRENTvelo.byte[0] = 200 * 256;
CURRENTvelo.byte[1] = 130;
velocity = CURRENTvelo.NUMvelo;
printf("%u\n", velocity);
} |
I expect the velocity value will be 200*256+130 =
51330
But instead, it shows result of 200*256 =
51200
Anyone knows how to solve this problem? Would kindly appreciate any help and suggestion. ;-)