I have two pieces of code supposed to do the same thing (read an unsigned 32-bit big-endian integer from a memory stream):
Code:return dword( ((static_cast<dword>(*source++)) << 24) | ((static_cast<dword>(*source++)) << 16) | ((static_cast<dword>(*source++)) << 8) | ((static_cast<dword>(*source++)) ) );However the second one works and the first always returns 0. Why?Code:dword d1, d2, d3, d4; d1 = *source++; d2 = *source++; d3 = *source++; d4 = *source++; dword ret = (d1 << 24) | (d2 << 16) | (d3 << 8) | d4; return ret;




CornedBee
Reply With Quote