C#有没有办法将字节[]/int32转换为int24?
我有一份档案。我从偏移量05读取了3个字节。那么如何将字节[]转换为int24呢?或者,如果我将该数组转换为int32,然后将该int32转换为int24,它会工作吗?如何转换?Int24不受直接支持,但有一个类似的问题描述了如何实现所需:C#有没有办法将字节[]/int32转换为int24?,c#,C#,我有一份档案。我从偏移量05读取了3个字节。那么如何将字节[]转换为int24呢?或者,如果我将该数组转换为int32,然后将该int32转换为int24,它会工作吗?如何转换?Int24不受直接支持,但有一个类似的问题描述了如何实现所需: public struct UInt24 { private Byte _b0; private Byte _b1; private Byte _b2; public UInt24(UInt32 value) { _b
public struct UInt24 {
private Byte _b0;
private Byte _b1;
private Byte _b2;
public UInt24(UInt32 value) {
_b0 = (byte)(value & 0xFF);
_b1 = (byte)(value >> 8);
_b2 = (byte)(value >> 16);
}
public unsafe Byte* Byte0 { get { return &_b0; } }
public UInt32 Value { get { return _b0 | ( _b1 << 8 ) | ( _b2 << 16 ); } }
我需要签名的int24。我只知道int24是3个字节:D@user1926930但您找不到类型Int24:DSee:
UInt24 uint24 = new UInt24( 123 );