====== C# Reading from and writing to byte array ====== 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)