java.nio.ByteBuffer problem.

Rutger Ovidius ovid@mailandnews.com
Fri Sep 19 05:01:00 GMT 2003


Is this supported with gcj? All I get are 0's.
gcc version 3.3.1 (mingw special 20030804-1)
---
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
public class Main {
public static void main (String [] args) {
	ByteBuffer bb = ByteBuffer.allocate(4);
	bb.order( ByteOrder.LITTLE_ENDIAN );
	bb.putInt(1111); // any #..
	System.out.println(toHexString(bb.array()));
}
public static String toHexString ( byte[] b ) 
{
	StringBuffer sb = new StringBuffer( b.length * 2 );
	for ( int i=0 ; i<b.length ; i++ )
	{
	sb.append( hexChar [ ( b[ i] & 0xf0 ) >>> 4 ] ) ;
	sb.append( hexChar [ b[ i] & 0x0f ] ) ;
	}
	return sb.toString() ; 
}
static char[] hexChar = 
{ 
'0' , '1' , '2' , '3' , 
'4' , '5' , '6' , '7' , 
'8' , '9' , 'a' , 'b' , 
'c' , 'd' , 'e' , 'f' } 
;
} 


More information about the Java mailing list

AltStyle によって変換されたページ (->オリジナル) /