C#如何提取字节数组?已知起始字节 [英] C# How to extract bytes from byte array? With known starting byte

查看:426
本文介绍了C#如何提取字节数组?已知起始字节的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要从一个字节数组得到具体的字节。我知道我要的第一个字节的内容,我需要X字节后。

例如,我有

 字节[] readbuffer {0,1,2,将0x55,3,4,5,6};
字节[] =结果新的字节[30];

和我需要将0x55

后出现的3个字节

 字节结果== {ox55aa,3,4,5}

我使用的是:

  Array.copy(readbuffer,将0x55需要的指数,结果,0,3);

我需要找到的将0x55指数

PS:将0x55 是数组中的一个偶然的位置。
PS2:我忘了提及此之前,我在.NET微架构正在工作。

(对不起了非code说明,我是一个非常新手编程...英文)

感谢您提前

X2


解决方案

 字节[] =结果新的字节[16];
        INT指数= Array.IndexOf(readBuffer,(字节)将0x55);
        Array.Copy(readBuffer,索引,结果,0,16);

感谢大家。

这是我的code现在。它的工作如我所料:)

I need to get specific bytes from a byte array. I know the content of the first byte I want and I need x bytes after that.

For example, I have

byte [] readbuffer { 0, 1, 2, 0x55, 3, 4, 5, 6};
byte [] results = new byte[30];

and I need the 3 bytes that appear after "0x55"

byte results == {ox55aa, 3, 4, 5}

I'm using:

Array.copy(readbuffer, "need the index of 0x55" ,results, 0, 3);

I need to find the index of 0x55

PS: 0x55 is in an aleatory position in the array. PS2: I forgot to mention before that I'm working in .Net Micro Framework.

(I'm sorry for the non code description, I'm a very newbie to programming... and english)

thank you in advance

[edited]x2

解决方案

        byte[] results = new byte[16];
        int index = Array.IndexOf(readBuffer, (byte)0x55);
        Array.Copy(readBuffer, index, results, 0, 16);

Thank you all.

This is my code now. it's working as I expect :)

这篇关于C#如何提取字节数组?已知起始字节的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆