You can do it like this (not bitwise, but maybe simpler):
unsigned int a;
char *c;
c = (char *)&a;
c[0] = 'w';
c[1] = 'o';
c[2] = 'r';
c[3] = 'd';
Or, if you want to be sized, you can use:
unsigned int a;
a &= ~(0xff << 24);
a |= ('w' << 24);
If you do not clear it first, you may get a different result.
source
share