How can I store 4 8 bit coordinates into one integer (C#)?

后端 未结 4 1023
面向向阳花
面向向阳花 2021-01-28 11:27

Lets say I have the following four variables: player1X, player1Y, player2X, player2Y. These have, for example, respectively the following values: 5, 10, 20, 12. Each of these va

4条回答
  •  广开言路
    2021-01-28 11:56

    To "squeeze" 4 8 bits value in a 32 bit space, you need to "shift" the bits for your various values, and add them together.

    The opposite operations is to "unshift" and use some modulo to get the individual numbers you need.

提交回复
热议问题