Ok - those low order words you created can only store 2-bit values. And in two bits you can only store 0, 1, 2 or 3 (decimal) - 11 is 3, 01 is 2, 10 is 1 and 00 is 0 (just to show all combinations).
So I want to store a 2 in the first-low order word. And I want to store a 3 in the second low order word. And I want to store that 5 in the high order nibble.
That's going to look like
0111 1010 (decimal 94)
Do you see that?
2+4+8 along with 16+64 - for a total of decimal 94
Now to see a word - I first shift it to the down and then mask it with a WORD mask. A WORD mask is a 3 (11).
And of course to mask a nibble we use 15 (1111).
I'll do this in the immediate window:
You just saw me take the 94 in the myByte variable and do three different shifts with 2 different masks and you saw my original values of 5, 3 and 2.Code:myByte = 0 myByte = myByte OR (2) ' store a 2 in the low order myByte = myByte OR (3 * 4) ' store a 3 in the next word (4 is the shift point) myByte = myByte OR (5 * 16) ' store a 5 in the high order nibble ? mybyte 94 'it's really a 94 - built in the fashion I've just shown ?(mybyte \ 16) AND 15 ' I'm using \ to force integer division ' if you have 16 as an INTEGER constant the math will remain INTEGER 5 ?(mybyte \ 4) AND 3 3 ?(myByte) AND 3 2




Reply With Quote