Convert C++ code to C#
See the question and my original answer on StackOverflow.NET's char is actually unicode, not like in c++. You should at least replace char by byte. Then, when you ultimately want a string from bytes, use the Encoding class, like this: Encoding.Default.GetString(bytes)...