I've currently written a code for converting a string to an array of bytes and then writing those bytes to an buffer byte array. However, for some reason, the alignment part of the code seems to stop the execution of the program. I've testing it enough to know that it's the "int DynamicAlign.." part, but I can't figure out why it's happening.
public void WriteStr( string myString )
{
byte[] myBytes = System.Text.Encoding.ASCII.GetBytes( myString );
for( int i = 0; i < myBytes.Length; i ++ )
{
Buffer[ BytePeek ] = myBytes[ i ];
BytePeek ++;
}
int DynamicAlign = ((myBytes.Length + 1) % ByteAlign != 0)
? ByteAlign - ((myBytes.Length + 1) % ByteAlign)
: 0;
BytePeek += (ushort)(1 + DynamicAlign);
}
If you don't know how byte alignment works, I found this as extra info: http://pastebin.com/tXzLWpBG
The extra "+ 1" and "1 +" are for taking into account the null terminating string at the end of the read sequence.