I am reversing a source code of a file writer, and here are the methods that read/write ints (or rather ushorts):
BinaryReader _Reader;
BinaryWriter _Writer;
void RawWriteInt16(int value)
{
byte a = (byte)(value & 255);
byte b = (byte)(value >> 8 & 255);
_Writer.Write(a);
_Writer.Write(b);
}
ushort RawReadUInt16()
{
int num = _Reader.ReadByte();
int num2 = _Reader.ReadByte();
return (ushort)((num2 << 8) + num);
}
So, can you explain why the & with 255(11111111) which is always the same and the shifting?
P.S. I need this for an article and will give you credit. You can check it here if you like, or on codeproject: Sequential-byte-serializer
Thanks for the interest. Credits have been given to @Sentry and @Rotem. I will post also the codeproject url when the article gets approved