I want tidy code that creates an opcode from two pieces, and encodes it as a little endian binary. Where “the OGF occupies the upper 6 bits of the Opcode, and the OCF occupies the remaining 10 bits.” This code is almost what I want, except that the resulting binary is big endian:
Careful with the Bitwise operators. ogf <<< 10 would only shift and not mask like <<ogf::6>>. Masking cuts off the extra bits. So as an expression it can be:
I guess you’d agree that’s hardly more readable. Alternatively you could create a handy swap16 function that swaps its bytes. Then you can have everything in one line and the intent is clear as day.
Trimming would have happened in the little-16 part. At least for ogf, but indeed I’ve forgotten about ocf (or did I just assume that data has been sanitizer already?)
Sorry, my fault, it was Bitwise, not Binary… That is the kind of stuff that happens when one replies to technical topics while waiting for the train home…