Joined: 09 May 2003 Posts: 25294 Location: The netherlands
Posted: Mon Mar 05, 2018 4:19 am Post subject:
Code:
function write5BitLongValueAtPos(value, bitvalue, bitpos)
return (value & (~(0x1f << bitpos))) | (bitvalue << bitpos)
end
0x1f is binary 11111
0x1f << bitpos means shift the bitmask 'bitpos' times to the left (e.g 2 turns into: 1111100)
~(1111100) turns into 11111111111111111111111110000011
value & the bitshifted mask zeroes out the bits that used to be at that position
(bitvalue << bitpos) moves the value to the specific binary position
value | shifted bitvalue , OR's the bits of bitvalue at the specific spot. And since earlier those bits got set to 0, that means the new value is the value you want _________________
Do not ask me about online cheats. I don't know any and wont help finding them.
Like my help? Join me on Patreon so i can keep helping
Last edited by Dark Byte on Mon Mar 05, 2018 4:20 am; edited 1 time in total
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum