bit manipulation - How do I store a byte into a 4 byte number without changing the bytes around it? -


so if have 4 byte number (say hex) , want store byte dd hex, @ nth byte position without changing other elements of hex's number, what's easiest way of going that? i'm guessing it's combination of bitwise operations, i'm still quite new them, , have found them quite confusing far?

byte n = 0xdd; uint = 0x12345678; = (i & ~0x0000ff00) | ((uint)n << 8); 

edit: forgot mention, careful if you're doing signed data types, things don't inadvertently sign-extended.


Comments

Popular posts from this blog

python - Why doesn't list have safe "get" method like dictionary? -

razor - Is this a bug in WebMatrix PageData? -

sql server - Stored procedure -