Is there a wrapper function directly?
CodePudding user response:
Public static byte [] IntArrToByteArr (int [] intArr){
Int intSize=sizeof (int) * intArr in Length;
Byte [] bytArr=new byte [intSize];
//apply for a block of unmanaged memory
IntPtr PTR=Marshal. AllocHGlobal (intSize);
//copy int array to the memory block
Marshal. Copy (intArr, 0, PTR, intArr. Length);
//copy to byte array
Marshal. Copy (PTR, bytArr, 0, bytArr. Length);
//release application of unmanaged memory
Marshal. FreeHGlobal (PTR);
Return bytArr;
}
CodePudding user response:
static async Task Main (string [] args)
{
Int I=3;
Var res=GetBit16Low (I). ToList ();
}
Public static IEnumerableGetBit16Low (int value)
{
Short I=(short) value;
BitArray BitArray=new BitArray (BitConverter GetBytes (I));
For (int j=bitArray Length - 1. J & gt;=0; J -)
{
Yield return the Convert. ToInt32 (bitArray [j]);
}
}
CodePudding user response:
The above is the use of Microsoft's existing functionIf you want to dazzle head moving wheels, moves to the right to add a judge
public static IEnumerableGetBit16Low1 (int value)
{
Int t=1;
For (int I=15; I & gt;=0; I -)
{
Var t1=1 & lt; If (value | (t1)==value)
Yield return 1;
The else
{
Yield return 0;
}
}
}
CodePudding user response:
Below the post something of the sales, of course, the following two you look pure, don't take it seriously, just pure skills, rather than technology1. Direct linq
Var b=Enumerable. Range (0, 16). The Select (p=& gt; ((1 & lt; <(15 - p) | value)==value)? 1:0);
2. To the third floor, the average person a see don't understand the
Public static IEnumerable
{
For (int I=15, t=1 & lt; 1)
{
Int r=value | (t)==value? 1:0;
Yield return r;
}
}
CodePudding user response: