Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DWORD to bytes using bitwise shift operators

Tags:

c++

I can't get it to work correctly.

#include <windows.h>

int main()
{
    DWORD i  = 6521;

    BYTE first = i >> 32;
    BYTE second = i >> 24;
    BYTE third = i >> 16;
    BYTE fourth = i >> 8;

    i = (((DWORD)fourth) << 24) | (((DWORD)third) << 16) | (((DWORD)second) << 8) | first;
}
like image 675
cpx Avatar asked Feb 17 '26 06:02

cpx


1 Answers

BYTE first = (i >> 24) & 0xff;
BYTE second = (i >> 16) & 0xff;
BYTE third = (i >> 8) & 0xff;
BYTE fourth = i & 0xff ;

Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!