X xuyingfeng Unregistered / Unconfirmed GUEST, unregistred user! 2001-11-13 #1 如何把一个int整数转换成一个byte[] 长度为4
D darkiss Unregistered / Unconfirmed GUEST, unregistred user! 2001-11-13 #4 i := 0 ; while i < 4do begin (c+i)^ := Char( (($FF000000 and ret) shr 24) and $000000FF ) ; ret := ret shl 8 ; inc(i) ; end ;
i := 0 ; while i < 4do begin (c+i)^ := Char( (($FF000000 and ret) shr 24) and $000000FF ) ; ret := ret shl 8 ; inc(i) ; end ;
J JJams_King Unregistered / Unconfirmed GUEST, unregistred user! 2001-11-13 #5 public final void writeInt(int v) throws IOException { OutputStream out = this.out; out.write((v >>> 24) & 0xFF); out.write((v >>> 16) & 0xFF); out.write((v >>> 8) & 0xFF); out.write((v >>> 0) & 0xFF); incCount(4); }
public final void writeInt(int v) throws IOException { OutputStream out = this.out; out.write((v >>> 24) & 0xFF); out.write((v >>> 16) & 0xFF); out.write((v >>> 8) & 0xFF); out.write((v >>> 0) & 0xFF); incCount(4); }
S spear Unregistered / Unconfirmed GUEST, unregistred user! 2001-11-15 #6 public final byte[] getBytes(int i) { byte[] b = new byte[4]; for(int j = 0; j < 4; j++) { b[j] = (byte)(i & 255); i >>= 8; } return b; }
public final byte[] getBytes(int i) { byte[] b = new byte[4]; for(int j = 0; j < 4; j++) { b[j] = (byte)(i & 255); i >>= 8; } return b; }
W wenyue Unregistered / Unconfirmed GUEST, unregistred user! 2001-11-15 #7 没这么麻烦吧, TYPE TMYARR=ARRAY[0..3] OF BYTE; PMYARR=^TMYARR; 将任何整数变量的地址强制成为PMYARR类型就可以当成长度为四的数组了. 例如可以使用 VAR I:INTEGER; 使用PMYARR(@I)^[0]就可以访问第一个元素了.
没这么麻烦吧, TYPE TMYARR=ARRAY[0..3] OF BYTE; PMYARR=^TMYARR; 将任何整数变量的地址强制成为PMYARR类型就可以当成长度为四的数组了. 例如可以使用 VAR I:INTEGER; 使用PMYARR(@I)^[0]就可以访问第一个元素了.
U ugvanxk Unregistered / Unconfirmed GUEST, unregistred user! 2001-11-15 #8 var a:array[0..3] of byte; b:int; move(b,a,4);