Ok so here is the deal. I am reading 1 byte at a time from a binary file. And then i put it in an int variable like this:
l = *rbyte;
l <<8;
<read another byte>
l |=*rbyte;
l <<8;
<read another byte>
l |=*rbyte;
l <<8;
<read another byte>
l |=*rbyte;
Now this should presumably work fine, and for binary data like 00 00 00 0D it is returning 13, and like that for 6 and 9. However for binary data 00 00 80 00, it is simply returning 128. When it should actually return 32768. What gives?
Because you aren’t assigning the result of your left shift to anything. The shift operators aren’t like
++and--they don’t automatically update their argument.Change your shift lines to