1 2 Previous Next 18 Replies Latest reply: Aug 6, 2007 5:39 PM by 807605 RSS

    why would one strip the least significant bits when casting?

    807605
      Hi,

      I've run across some undocumented code that in converting shorts and bytes to ints.

      For example,
      short s = myDataInputStream.readShort();
       int i = myshort & 0x0000ffff;
      Based on where this code is used, it seems to be doing a "cleansing" of some type to the value, at at least that is what the original author thought he was doing. But since a short in Java is two bytes, is there any case where and'ing it with FFFF will do anything meaningful? Unless I'm missing something it seems like you'd always get the same answer back after the operation.

      Thank you
        1 2 Previous Next