I want to add two 32-bit values into byte[8]
in big endian style.
int a = 1; // => [ 0, 0, 0, 1]
int b = 2; // => [ 0, 0, 0, 2]
resulting in
[0, 0, 0, 1, 0, 0, 0, 2]
So what is the one liner for this?
My approach so far was
int a = 1;
int b = 2;
byte[] array = new byte[] { };
array = array.Concat(BitConverter.GetBytes(a)).ToArray();
array = array.Concat(BitConverter.GetBytes(b)).ToArray();
so this is already complicated enough but little endian. So I would add a line for each int
to get them reversed.
Two talk in python:
a = 1;
b = 2;
array = a.to_bytes(4, 'big') + b.to_bytes(4, 'big')
What is the C# method for this?