/* source with short values */ public List<short> Data = new List<short>(); ... short[] DataArray = Data.ToArray(); byte[] bufferBytes = new byte[ DataArray.Length * sizeof( short ) ]; Buffer.BlockCopy( DataArray, 0, bufferBytes, 0, bufferBytes.Length ); /* dest with byte values */ Console.WriteLine( bufferBytes[0] + ", " + bufferBytes[1] );If first short value in source list is 313, then first two values in bufferBytes after copy will be 57 (111001) a 1(1).
Microsoft AX 2012, X++, C#, SQL server, SSRS, Java, JavaFX, Oracle, PL/SQL, Delphi - codes examples, step-by-step tutorials, experiences.
Friday, December 18, 2020
C# - How to convert short array/list into byte array list
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment