Bonjour,
j'ai un byte et je souhaiterai avoir sa valeur en unsigned byte...
Ou comment convertir mon byte en unsigned byte ?
Comment faire ?
Merci...
Version imprimable
Bonjour,
j'ai un byte et je souhaiterai avoir sa valeur en unsigned byte...
Ou comment convertir mon byte en unsigned byte ?
Comment faire ?
Merci...
8OCode:
1
2
3
4
5
6
7
8
9
10
11 byte signed = -1; /** @see http://forum.java.sun.com/thread.jspa?threadID=569750&messageID=2817623 */ int unsigned = (signed & 0xff); System.out.println(unsigned); // 255 /** @see http://forum.java.sun.com/thread.jspa?threadID=511332&messageID=2429897 */ unsigned = (signed >= 0 ? signed : 256 + signed); System.out.println(unsigned); // 255 /** @author g_rare */ unsigned = (256 + signed) % 256; System.out.println(unsigned); // 255
ouais le plus simple c'est & 0xff.
merci...