大端 小端
时间:2007-05-28 来源:nongdi
小端
0000000 00c8 0000 6261 6463 0065 0064 0000 0000
0000010 0000 0000 0000 0000 0000 0000 0000 0000
* 大端
0000100 0000 c800 6261 6463 0065 0000 6400 0000
0000110 0000 0000 0000 0000 0000 0000 0000 0000 import java.nio.*;
import java.io.*; public class Byte
{
public static void main(String[] args)
{
try
{
ByteBuffer bb = ByteBuffer.allocate(256);
System.out.println("order=" + bb.order());
//bb.order(ByteOrder.nativeOrder());
System.out.println("order=" + bb.order());
bb.putInt(200);
byte[] bt = new byte[6];
int i=0;
bt[i++] = 'a';
bt[i++] = 'b';
bt[i++] = 'c';
bt[i++] = 'd';
bt[i++] = 'e';
bt[i++] = 0;
bb.put(bt);
bb.putInt(100);
File file = new File("a.bin");
FileOutputStream fos = new FileOutputStream(file, true);
fos.write(bb.array());
System.out.println("bb=." + bb + ".");
fos.close();
}catch(Exception e) { e.printStackTrace(); }
}
}
0000010 0000 0000 0000 0000 0000 0000 0000 0000
* 大端
0000100 0000 c800 6261 6463 0065 0000 6400 0000
0000110 0000 0000 0000 0000 0000 0000 0000 0000 import java.nio.*;
import java.io.*; public class Byte
{
public static void main(String[] args)
{
try
{
ByteBuffer bb = ByteBuffer.allocate(256);
System.out.println("order=" + bb.order());
//bb.order(ByteOrder.nativeOrder());
System.out.println("order=" + bb.order());
bb.putInt(200);
byte[] bt = new byte[6];
int i=0;
bt[i++] = 'a';
bt[i++] = 'b';
bt[i++] = 'c';
bt[i++] = 'd';
bt[i++] = 'e';
bt[i++] = 0;
bb.put(bt);
bb.putInt(100);
File file = new File("a.bin");
FileOutputStream fos = new FileOutputStream(file, true);
fos.write(bb.array());
System.out.println("bb=." + bb + ".");
fos.close();
}catch(Exception e) { e.printStackTrace(); }
}
}
相关阅读 更多 +