What are the codes doing?

S

Skyhorse

What are the following codes doing? What are the meaning of & 0xffe00000, &
3, 0xf, 0x3?
Is there any difference between & 3 and & 0x3?

inline BOOL CheckAudioHeader(DWORD dwHeader)
{
if ( (dwHeader & 0xffe00000) != 0xffe00000)
return FALSE;
if (!((dwHeader >> 17) & 3))
return FALSE;
if ( ((dwHeader >> 12) & 0xf) == 0xf)
return FALSE;
if ( ((dwHeader >> 10) & 0x3) == 0x3)
return FALSE;

#ifdef _WIN32_WCE
if ( ((dwHeader >> 12) & 0xf) == 0x0)
return FALSE;
#endif

return TRUE;
}

Thanks
 
P

Peter van Merkerk

Skyhorse said:
What are the following codes doing? What are the meaning of & 0xffe00000, &
3, 0xf, 0x3?
Is there any difference between & 3 and & 0x3?

inline BOOL CheckAudioHeader(DWORD dwHeader)
{
if ( (dwHeader & 0xffe00000) != 0xffe00000)
return FALSE;
if (!((dwHeader >> 17) & 3))
return FALSE;
if ( ((dwHeader >> 12) & 0xf) == 0xf)
return FALSE;
if ( ((dwHeader >> 10) & 0x3) == 0x3)
return FALSE;

Let me guess: a MPEG audio (MP3) header check?
Hexadecimal numbers are prefixed by 0x. And you are right hexadecimal 3
equals decimal 3. 0xffe00000 represents a hexadecimal number with the 11
most significant bits set. The header of every MPEG audio frame always
start with at least 11 ones. So that is what the first if is for. The bit
fields that follow in an MPEG header never have all bits set, and that is
what is being checked in the if's that follow.
 
C

Chris Dams

Hi!

Skyhorse said:
What are the following codes doing? What are the meaning of & 0xffe00000, &
3, 0xf, 0x3?
Is there any difference between & 3 and & 0x3?

These are hexadecimal numbers. 3 == 0x3 but this is no longer true if
numbers get larger than nine. 10 == 0xa, 11 == 0xb, ..., 15 == 0xf,
16 == 0x10, 17 == 0x11, 18 == 0x12, ..., 21 == 0x1f and so on.

Bye,
Chris Dams
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,164
Messages
2,570,898
Members
47,440
Latest member
YoungBorel

Latest Threads

Top