1 intercept byte[] Part of the data, starting from begin, length is count
-(void) Bytesplit2byte: (byte[]) src orc: (byte[]) ORC begin: (Nsinteger) Begin count: (Nsinteger) count{
memset (orc, 0, sizeof (char) *count);
for (Nsinteger i = begin; I < Begin+count; i++) {
Orc[i-begin] = Src[i];
}
}
2 The byte array is converted to data of type int, which provides a storage idea
-(int) Lbytestoint: (byte[]) Byte
{
int height = 0;
NSData * TestData =[nsdata datawithbytes:byte length:4];
for (int i = 0; i < [testData length]; i++)
{
if (byte[[testdata Length]-i] >= 0)
{
Height = height + byte[[testdata length]-i];
} else
{
Height = height + 256 + byte[[testdata length]-i];
}
Height = height * 256;
}
if (Byte[0] >= 0)
{
Height = height + byte[0];
} else {
Height = height + 256 + byte[0];
}
return height;
}
3 turn int into byte[]
int jsonlen = Jsondata.length;
Char *p_json = (char *) &jsonlen;
Char Str_json[4] = {0};
for (int i= 0; i < 4; i++)
{
Str_json[i] = *p_json;
P_json + +;
}
Specific use of local, for example, custom socket protocol. The data size needs to be passed in, and the length of the int needs to be converted to byte[] so that it can be placed in the byte of the corresponding protocol