Java - bit shifting with integers and bytes
Consider the following code (where byteIndex is an int): int bitNumber = b-(8*byteIndex); bitMask = 0x8>>(byte)bitNumber; This generates the error error: possible loss of precision when compiled (required byte, found int). The code int bitNumber = b-(8*byteIndex); bitMask = 0x8>>2; compiles fine. What is the problem here and how do I fix the first example to allow bit shifting by the int value? EDIT: Following the comments, here is a more-complete example: 48) int byteIndex; 49) byte bitMask; 50) int bitNumber; // assign value to byteIndex 67) bitNumber = b-(8*byteIndex); 68) bitMask = 0x8>