public static void CopyHexBufferToBuffer(char[] hexBuffer, int offset, int count, byte[] buffer, int bufferOffset)
{
if (hexBuffer == null) throw new ArgumentNullException("hexBuffer");
if (offset < 0) throw new ArgumentOutOfRangeException("offset");
if (offset + count > hexBuffer.Length) throw new ArgumentOutOfRangeException("offset");
if (count < 0) throw new ArgumentOutOfRangeException("count");
if (buffer == null) throw new ArgumentNullException("buffer");
if (bufferOffset < 0) throw new ArgumentOutOfRangeException("bufferOffset");
if (bufferOffset + (count + 1) / 2 > buffer.Length) throw new ArgumentOutOfRangeException("count");
if (count == 0)
return;
var end = offset + count;
for (; offset < end; offset += 2, bufferOffset++)
buffer[bufferOffset] = ToUInt8(hexBuffer, offset);
}