Changeset 5970
- Timestamp:
- 01/31/08 23:28:32 (5 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
lang/java/jimmy/trunk/jimmy/src/main/java/jimmy/ConvertUtil.java
r5805 r5970 15 15 */ 16 16 package jimmy; 17 18 import java.net.InetAddress; 19 import java.net.UnknownHostException; 17 20 18 21 import org.apache.commons.codec.binary.Hex; … … 59 62 60 63 public static int littleEndianBytes2int( byte[] bs ) { 61 // uncheck byte length. maybe 4bytes!! 62 return ( ( bs[3] & 0xFF ) << 24 ) | ( ( bs[2] & 0xFF ) << 16 ) | ( ( bs[1] & 0xFF ) << 8 ) | 63 ( ( bs[0] & 0xFF ) ); 64 /* 65 * 柔軟に対応してみるテスト 66 */ 67 int i = ( bs.length > 3 ) ? ( ( bs[3] & 0xFF ) << 24 ) : ( ( 0 & 0xFF ) << 24 ); 68 i = i | ( ( bs.length > 2 ) ? ( ( bs[2] & 0xFF ) << 16 ) : ( ( 0 & 0xFF ) << 16 ) ); 69 i = i | ( ( bs.length > 1 ) ? ( ( bs[1] & 0xFF ) << 8 ) : ( ( 0 & 0xFF ) << 8 ) ); 70 i = i | ( ( bs.length > 0 ) ? ( bs[0] & 0xFF ) : ( 0 & 0xFF ) ); 71 return i; 64 72 } 65 73 … … 79 87 System.out.println( Hex.encodeHex( toLittleEndianBytes( 123456789 ) ) ); 80 88 System.out.println( littleEndianBytes2int( new byte[] { 0x15, (byte) 0xCD, 0x5B, 0x07 } ) ); 89 try { 90 System.out.println( InetAddress.getByAddress( 91 new byte[] { (byte) 0xC0, (byte) 0xA8, (byte) 0x01, 92 (byte) 0x0A } ).getHostAddress() ); 93 } 94 catch ( UnknownHostException e ) { 95 e.printStackTrace(); 96 } 97 System.out.println( littleEndianBytes2int( new byte[] { (byte) 0xC0, (byte) 0xA8 } ) ); 98 System.out.println( littleEndianBytes2int( new byte[] { (byte) 0xC0, (byte) 0xA8, 0, 0 } ) ); 81 99 } 82 100 }
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)