- 632 名前:デフォルトの名無しさん mailto:sage [2008/05/31(土) 03:58:37 ]
- short と byte[] の相互変換ってどうやるんですか?
private byte[] ShortToByte( short s ) { byte [] b = { (byte)((s >> 8) & 0xFF), (byte)((s >> 0) & 0xFF) } ; return b; } private int ByteToShort( byte []b ) { return ((b[0] & 0xff) << 8) | (b[1] & 0xff); } こんなのを作ってみましたけど 上手く行きません short s = -1; System.out.println( s ); System.out.println( ByteToShort( ShortToByte( s ) ) ); 結果 -1 65535
|

|