Longs and bitwise stuff.
BlitzMax Forums/BlitzMax Beginners Area/Longs and bitwise stuff.
| ||
I've got an array of Longs with a typical value of $20FFFFFF00004000. I want to be able to change the first byte (the $20) to any arbitrary value, leaving all other bits unchanged. I'm having a late-night brain fart and cannot think how to do it. I'm going to bed now because I'm obviously dumb and tired :) If anyone can point out a way of achieving this simple task, I would be eternally grateful :D |
| ||
edited as it was wrong |
| ||
Or'ing will combine with existing data in that byte. If there's a previous value there it will turn into something unwanted. Also shifting left 64 bits shifts the value entirely out of the range of the long, into a 9th byte. You also need to do an AND first to `clear` the byte. value:& $00FFFFFFFFFFFFFF value:| (secondvalue shl 56) Note that secondvalue, as a variable, should be a Long variable, or it will become empty when shifting past bit 31. Or, you can cast it as a Long: value:| (Long(secondvalue) Shl 56) |