Java virtual machine always used big-endian, Intel x86 used little-endian.
public class Swab {
public final static int swabInt(int v) {
return (v >>> 24) | (v << 24) |
((v << 8) & 0x00FF0000) | ((v >> 8) & 0x0000FF00);
}
public static void main(String argv[]) {
// before 0x01020304
// after 0x04030201
int v = 0x01020304;
System.out.println("before : 0x" + Integer.toString(v,16));
System.out.println("after : 0x" + Integer.toString(swabInt(v),16));
}
}
Deal with big-endian and little-endian order
最新推荐文章于 2021-12-03 23:46:31 发布