BlockCopy alternative that allows me to choose a limb

Say I have an array of bytes:

byte[] input = { 0xFF, 0xFc, 0x00, 0x00 }

You can use Buffer.BlockCopyto copy bytes from one array to another, regardless of type. So, I can do this:

uint[] output = new uint[1];
Buffer.BlockCopy(input , 0, output, 0, input.Length);

This will copy the bytes from input to output, converting them from the byte array to the uints array along the way.

The problem is that it BlockCopyinterprets bytes with little precision. I need a copy using a large continent. Therefore, instead of getting the value uint 4294705152 (0xFFFC0000), like me, I get the value 64767 (0x0000FCFF). Please note that this is an example with blue bones, I cannot easily change the byte order in my actual application.

Is there anything with convenience and speed BlockCopy, which includes the ability to establish the entity I need?

+4
source share
1 answer

The topic seems to be addressed here:

How to get small final data from a large endian in C # using the bitConverter.ToInt32 method?

However, the conversion must be repeated throughout the input array.

+2
source

Source: https://habr.com/ru/post/1532258/


All Articles