development:csharp:converting_bytes

no way to compare when less than two revisions

Differences

This shows you the differences between two versions of the page.


development:csharp:converting_bytes [2021/05/20 20:22] (current) – created - external edit 127.0.0.1
Line 1: Line 1:
 +====== C# Reading from and writing to byte array ======
 +<code c#>
 +Byte[] ByteName = new Byte[101];                                 // Declare bytearray
 +Buffer.BlockCopy(bytes, 0, ByteName, 0, 101);                    // Copy part of byte array (bytes) to ByteName
 +string Name = Encoding.UTF8.GetString(ByteName).TrimEnd('\0');   // Convert to string, and trim
  
 +bytes[100]                             // UInt8 on location 100
 +BitConverter.ToUInt16(bytes, 101);     // UInt16 on location 101 (has length 2 bytes)
 +BitConverter.ToUInt32(bytes, 103);     // UInt32 on location 103 (has length 4 bytes)
 +BitConverter.ToUInt32(bytes, 107);     // UInt64 on location 107 (has length 8 bytes)
 +            
 +string name = "text" + char.MinValue;  // Null terminate string
 +
 +BitConverter.GetBytes(bool);         // Get bytes from value
 +Encoding.ASCII.GetBytes(string)
 +</code>
  • development/csharp/converting_bytes.txt
  • Last modified: 2021/05/20 20:22
  • by 127.0.0.1