Dave’s Brain
Home
Search
Browse
Recent
Keywords
Other sites
Feedback
Sign in
Random
Crawlers
Programming Tips
- Java: Convert a byte to an int or long
Date:
2012feb10
Language:
Java
Q.
Java: Convert a byte to an int or 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
;