Programming Tips - How can I convert a byte to a long

Date: 2012feb10 Language: Java Q. How can I convert a byte to a long A. You probably want to AND with 0xff to avoid sign extension:
long mylong = mybyte & 0xff;
Similarly when going to an int:
int myint = mybyte & 0xff;