I have a group of integers that I want to send over a socket connection. What would be the cleanest way to convert the following variables into a byte array?
int var1 = 1;
int var2 = 2;
int var3 = 3;
Because I'm sending data via sockets, I would like to format the data using big-endianness. Thus for the three variables listed, I would want a 12 byte array such that
byte[0] = 0;
byte[1] = 0;
byte[2] = 0;
byte[3] = 1;
byte[4] = 0;
byte[5] = 0;
byte[6] = 0;
byte[7] = 2;
byte[8] = 0;
byte[9] = 0;
byte[10] = 0;
byte[11] = 3;
My search results are surprisingly coming up empty.
Edit: The suggested duplicate questions are different from what I'm asking. I do not have an "array of integers" or "a single integer" that I want to convert to a byte array. I have a group of individual array variables and am looking for the cleanest solution.