Ignacio Machin ( .NET/ C# MVP ) napisal(a):
Hi,
What is wrong with that? It sure is fast
The other only possible solution is to convert the int to byte using
BitConverter.GetBytes() and then array.Copy
--
Ignacio Machin
machin AT laceupsolutions com
"JohnShade" <pr**************@poczta.onet.plwrote in message
news:11**********************@t46g2000cwa.googlegr oups.com...
sorry for my bad english
i ve array of bytes, byte[] data
i wanna put an int into this array on some arbitrary position
how is the better way to do this?
in this moment i only can do some thing like that
int pos=17;
int myintval = 0xaabbccdd;
data[pos+0]= (byte) (myintva>>24)%256;
data[pos+1]= (byte) (myintva>>16)%256;
data[pos+2]= (byte) (myintva>>8)%256;
data[pos+3]= (byte) (myintva>>0)%256;
above is my endian-type mistake, couse it should be
data[2]=(byte) ((myintva>>00)%256);
data[3]=(byte) ((myintva>>08)%256);
data[4]=(byte) ((myintva>>16)%256);
data[5]=(byte) ((myintva>>24)%256);
or
data[2]=(byte) ((myintva & 0x000000FF) >>00 );
data[3]=(byte) ((myintva & 0x0000FF00) >>08);
data[4]=(byte) ((myintva & 0x00FF0000)>>16);
data[5]=(byte) ((myintva & 0xFF000000) >>24);
which is far better to read i agree : )
I am suprised that in c# it probably is nothing that is "shorter in
text"
and would do that what i can write as byte[] << int32
like *((int32*) &data[17]) = 0xaabbccdd or what it was like in c
but whatever, TNX
JSh