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

后端 未结 4 1017
面向向阳花
面向向阳花 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 12:18

    Here is an alterantive:

    Make a struct with defined packing. Expose:

    • The int32 and all 4 bytes at the same time
    • Make sure the apcking overlaps (i.e. int starts at 0, byte variables at 0, 1,2,3

    Done.

    And you can easily access and work with them WITHOUT a bitconverter et al and never have to define an array, which is expensive jsut to throw it away.

提交回复
热议问题