1、可以在文件里面保存为有符号整形,但是读入到内存变成无符号的。
2、可以在文件里面保存为无符号整形,但是读入到内存变成有符号的。
// testSignelToUnsign.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <stdio.h>
#include <stdlib.h>
#include <memory.h>
int main(int argc, char* argv[])
{
char szBuf[] = "-1";
int s_int = 0;
unsigned int us_int = 0;
s_int = atoi(szBuf);
printf("s_int:%d\n", s_int);//---- -1
us_int = (unsigned int)atoi(szBuf);
printf("us_int:%u\n", us_int);//---- 4294967295
memcpy(&us_int, &s_int, sizeof(unsigned int));
printf("us_int:%u\n", us_int);//---- 4294967295
return 0;
}
#include "stdafx.h"
#include <stdio.h>
#include <stdlib.h>
#include <memory.h>
int main(int argc, char* argv[])
{
char szBuf[] = "4294967295";
int s_int = 0;
unsigned int us_int = 0;
s_int = atoi(szBuf);
printf("s_int:%d\n", s_int);//---- -1
us_int = (unsigned int)atoi(szBuf);
printf("us_int:%u\n", us_int);//---- 4294967295
memcpy(&us_int, &s_int, sizeof(unsigned int));
printf("us_int:%u\n", us_int);//---- 4294967295
return 0;
}