First thing is to isolate each 4LSB of each variable. Easy way, using boolean AND (&)"Z" holds
A= 0-3,
B= 4-7,
C=8-11,and
D=12-15.
Now, you need to shift some bits of your Bytes variables. This is done using left shift (<<). Check your manual about that. Knowing that, we could modify the above likeCode:A = A & $0F B = B & $0F C = C & $0F D = D & $0F
Now you need to combine A & B, and C & D, then the whole thing together. Boolean OR do the trickCode:A = A & $0F B = B << 4 C = C & $0F D = D << 4
Then you need to send A and C where they're suppose to go in ZCode:A = (A & $0F) | (B <<4) ' a hold A & B C = (C & $0F) | (D <<4) ' C hold C & D
A is now LSB of Z(0-7), C is now MSB of Z(8-15).Code:Z.LowByte = A Z.HighByte = C
This could be shorten like
If you're REALLY SURE you NEVER EVER mess with bits <7:4> of your variables, then yes, this could reduce toCode:Z.LowByte = (A & $0F) | (B <<4) Z.HighByte = (C & $0F) | (D <<4)
ORCode:Z.HighByte = (D<<4) | C Z.LowByte = (B<<4) | A
I see other ways, but this should be more than enough to startCode:Z = (D<<12) | (C<<8) | (B<<4) | A![]()





Bookmarks