最近在做項目中涉及到網(wǎng)絡(luò)傳輸字節(jié)流的問題;client端分成字節(jié)進行傳輸,server端接收后需要
將其組成整形進行數(shù)據(jù)庫存儲,方法如下:
1
#include <stdio.h>
2
3
int main(void)
4
{
5
unsigned char array[4] = {"0x0","0x0","0x02","0xe7"};
6
unsigned long num;
7
num = 0;
8
for(int i=0; i<sizeof(array); i++)
9
{
10
num<<=8;
11
num |= array[i];
12
}
13
printf("num = %d",num);
14
return 0;
15
16
}
#include <stdio.h>2

3
int main(void)4
{5

unsigned char array[4] = {"0x0","0x0","0x02","0xe7"};6
unsigned long num;7
num = 0;8
for(int i=0; i<sizeof(array); i++)9

{10
num<<=8;11
num |= array[i];12
}13
printf("num = %d",num);14
return 0;15
16
}

