4 ms·
EDIT: I misunderstood how it works, read the reply to see why I was in the wrong. I haven't read it all (and probably won't, these kinds of works are not my fo
by JaumeGreen 4y ago
EDIT: I misunderstood how it works, read the reply to see why I was in the wrong.
I haven't read it all (and probably won't, these kinds of works are not my forte), but there's something that doesn't look that nice.
The swapped function seems strange, mostly because you treat 1 as a special case which reverses the content.
I would either have a reverse function or use negative numbers to reverse those chunks, like this:
uint(16,0xc01f) matches big endian 0xc01f (bit sequence 1,1,0,0,0,0,0,0,0,0,0,1,1,1,1,1).
swapped(8, uint(16,0xc01f)) (bit sequence 0,0,0,1,1,1,1,1,1,1,0,0,0,0,0,0).
swapped(-16, uint(16,0xc01f)) (bit sequence 1,1,1,1,1,0,0,0,0,0,0,0,0,0,1,1).
swapped(-8, uint(16,0xc01f)) (bit sequence 1,1,1,1,1,0,0,0, 0,0,0,0,0,0,1,1).
swapped(-4, uint(16,0xc01f)) (bit sequence 0,0,0,0, 1,1,0,0, 1,1,1,1, 1,0,0,0).
There might be better solutions, I just dislike exceptions in rules, if it can be helped.
- kstenerud 4y agoSwap reverses all bits in chunks of the granularity size. So given bits = ABCDEFGHIJKLMNOP, you get: swapped(8, bits) -> IJKLMNOPABCDEFGH swapped(4, bits) -> MNOPIJKLEFGHABCD swapped(2, bits) -> OPMNKLIJGHEFCDAB swapped(1, bits) -> PONMLKJIHGFEDCBA So the full bit reversal when granularity = 1 is emergent phenomena rather than an exception.
- JaumeGreen 4y agoOk, that is more understandable. If there were some more examples in the page then this emergent behaviour could be seen faster. Nothing to add then
- kstenerud 4y agoCool! Even this feedback is important. This document needs to be accessible and easy to grasp, otherwise it has a UX problem.