Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/three.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C#有没有办法将字节[]/int32转换为int24?_C# - Fatal编程技术网

C#有没有办法将字节[]/int32转换为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

我有一份档案。我从偏移量05读取了3个字节。那么如何将字节[]转换为int24呢?或者,如果我将该数组转换为int32,然后将该int32转换为int24,它会工作吗?如何转换?

Int24不受直接支持,但有一个类似的问题描述了如何实现所需:

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 );