Well, most CPUs never operate on bits in main memory directly. Instead, data first needs to be loaded into registers of the CPU and are then operated on there. Also in this case, most CPU instructions work on multiple registers, e.g., using one for input and another for output. Thus, bits are not shifted in place, but you get fresh new bits holding your result in another register. From there you can then move it into memory again.
If you happen to put it into the same address as you originally loaded the data from, the whole operation can be considered in place β even though the hardware instructions did not work on the memory in place.
Bitshift instructions are useful as they are comparably easy to do with transistors and thus very fast, i.e., the corresponding hardware instructions take less time than more complex stuff such as multiplication.
1 Like
That makes a lot of sense, thanks!
Many programming terms like low-level and functional are getting misused here. Misunderstanding mutability is more understandable because the concept does vary across languages, though I donβt think any have considered pure functions to be mutating. For example, x = 0; x += 1
does not involve mutable types in Julia, but reassignment requires a mutable variable in F# and is not even allowed in many functional languages to enforce referential transparency.
1 Like
Well, F# allows shadowing. Is this also, what happens in this example?