Byte variable and buffer question
Don M
Posts: 1,652
Lets say I have this:
Where Inventory contains the quantity in bits 7-4 and the item number in bits 3-0. The Items buffer just contains the quantities (from 00 to FF) of 16 different items designated by byte position 0 as item 1, byte position 1 as item 2, etc...
If I receive an Inventory byte value such as $13 which would represent a quantity of 1 (0001) of item number 3 (0011) how do I parse or breakout the quantity bits and the item number bits so that I can adjust the item number's quantity in the Items buffer?
I know that I would want to do something like this:
I don't know how to break down the byte into bits and get what I need.
Thanks.
Don
var byte Inventory, Items[16]
Where Inventory contains the quantity in bits 7-4 and the item number in bits 3-0. The Items buffer just contains the quantities (from 00 to FF) of 16 different items designated by byte position 0 as item 1, byte position 1 as item 2, etc...
If I receive an Inventory byte value such as $13 which would represent a quantity of 1 (0001) of item number 3 (0011) how do I parse or breakout the quantity bits and the item number bits so that I can adjust the item number's quantity in the Items buffer?
I know that I would want to do something like this:
a := byte[@Items][?] (? = the item number from the item bits of Inventory) ' to get the quantity of ? item number a := a + ? (? = the quantity bits from Inventory) ' to add to the existing quantity number byte[@Items][?] := a ' to store the new quantity number of ? item number
I don't know how to break down the byte into bits and get what I need.
Thanks.
Don
Comments
...where idx is the index of the item you want to examine.
Here is what I got out of your suggestion and it works the way I need it too.
Thanks!
Don
INB:=items[x]
highbits:=INB[31..28]
lowbits:=INB[3..0]