Little Endian To Short Returning Negative?


  • Hey guys, so I have been working on a Opcode reader for a C# program of mine. It works great, but all the bytes are in little endian so it gets a little annoying at times. Well I ran into a slight problem tonight.

    Lets take these little endian bytes:

    00 B8

    The original was:

    B8 00

    After using this C# code

    return (short)((ReadByte()) | (ReadByte() << 8));

    Which is pretty self explanatory, I get FFFFB800 which is close but its negative!

    I don't want to use any BitConverter classes or anything, just hands on math because I will

    be porting this code later. Anyways, what am I doing wrong here? I can't seem to figure it out. Thanks guys

    Yours truly,


    Saturday, November 09, 2013 9:42 AM


All replies