首页 > 代码库 > C++ unsigned long 转化为 unsigned char*

C++ unsigned long 转化为 unsigned char*

C++ Code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
 
unsigned long lFileLen = 1000;

unsigned char *ucFileLenFlag;

ucFileLenFlag = (unsigned char *) &lFileLen; //方法一



//方法二:

ucFileLenFlag = new unsigned char [4];//数组指针

ucFileLenFlag[3] = ((unsigned char *)&lFileLen)[3]; //取i(long)最高位
ucFileLenFlag[2] = ((unsigned char *)&lFileLen)[2];
ucFileLenFlag[1] = ((unsigned char *)&lFileLen)[1];
ucFileLenFlag[0] = ((unsigned char *)&lFileLen)[0]; //取i(long)最低位

C++ unsigned long 转化为 unsigned char*