- #1
Silicon Waffle
- 160
- 203
In Win32 API, I see the define macro MAKEWORD
#define MAKEWORD( h, l ) \
( ( ( WORD )( h ) << 8 ) | ( BYTE )( l ) )
Why does it make a shift of 8 bits ?
In C#, they have a BitConverter.ToInt32, which performs something similar to this Makeword and I use this 8 bit shift and it works correctly. But they also have ToInt16 which shifting like this works correctly too in some of my cases. I'm so confused about 32 and 16 in this case.
That is, at some places where I change makeword to make a shift of 16, it works correctly whereas at others where shifting 16 is required, the output then becomes incorrect since shifting 8 is more precise.
It looks like casting is the issue but how
#define MAKEWORD( h, l ) \
( ( ( WORD )( h ) << 8 ) | ( BYTE )( l ) )
Why does it make a shift of 8 bits ?
In C#, they have a BitConverter.ToInt32, which performs something similar to this Makeword and I use this 8 bit shift and it works correctly. But they also have ToInt16 which shifting like this works correctly too in some of my cases. I'm so confused about 32 and 16 in this case.
That is, at some places where I change makeword to make a shift of 16, it works correctly whereas at others where shifting 16 is required, the output then becomes incorrect since shifting 8 is more precise.
It looks like casting is the issue but how
PHP:
int MAKEWORD(const int*& val, const int& index)
{
return (int)(((int)(val[index + 1]) << 16) + (short)(val[index]));
}
Last edited: