C# 字节数组截取
C# 字節數組截取
如: byte[] bt = new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
方法一 截取位數規則
1)截取2位長度的字節數組
用BitConverter.ToInt16
例如,從第2位開始截取2個字節則 BitConverter.ToInt16(bt,2);
2)截取4位長度的字節數組
用BitConverter.ToInt32
例如,從第3位開始截取4個字節則 BitConverter.ToInt32(bt,3);
3)截取8位長度的字節數組
用BitConverter.ToInt64
例如,從第4位開始截取8個字節則 BitConverter.ToInt64(bt,4);
方法二 截取的位數不規則
使用方法:
.Skip().Take().ToArray()
例如,從第2位開始截取4個字節則 bt.Skip(2).Take(4).ToArray();
總結
- 上一篇: python3操作sqite3删除数据表
- 下一篇: Python FastAPI 框架 操作