Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to reverse the order of a byte array in c#?

Tags:

c#

bytearray

How do you reverse the order of a byte array in c#?

like image 802
Edward Avatar asked Apr 25 '11 23:04

Edward


People also ask

How do you invert a byte Array?

You can use the Array. Reverse() method.

What is reverse byte order?

Description. The Byte Reversal block changes the order of the bytes in data that you input to the block. Use this block when a process communicates between target computers that use different endianness, such as between Intel® processors that are little endian and other processors that are big endian.

How do you reverse a byte in C++?

Reverse Bits in C++ answer := answer OR (n AND i), and shift it to the left i times. n := n after right shifting 1 bit.


1 Answers

You could use the Array.Reverse method:

byte[] bytes = GetTheBytes();
Array.Reverse(bytes, 0, bytes.Length);

Or, you could always use LINQ and do:

byte[] bytes = GetTheBytes();
byte[] reversed = bytes.Reverse().ToArray();
like image 162
Harry Steinhilber Avatar answered Sep 28 '22 13:09

Harry Steinhilber