字符串转换为数字(完整标准版)
来源:互联网 发布:cf彩虹哥淘宝 编辑:程序博客网 时间:2024/05/01 13:22
- //copyright@njnu_mjn 2013
- int StrToDecInt(const char* str)
- {
- static const int MAX = (int)((unsigned)~0 >> 1);
- static const int MIN = -(int)((unsigned)~0 >> 1) - 1;
- static const int MAX_DIV = (int)((unsigned)~0 >> 1) / 10;
- static const int MIN_DIV = (int)((((unsigned)~0 >> 1) + 1) / 10);
- static const int MAX_R = (int)((unsigned)~0 >> 1) % 10;
- static const int MIN_R = (int)((((unsigned)~0 >> 1) + 1) % 10);
- int n = 0;
- int sign = 1;
- int c;
- while (isspace(*str))
- ++str;
- if (*str == '+' || *str == '-')
- {
- if (*str == '-')
- sign = -1;
- ++str;
- }
- while (isdigit(*str))
- {
- c = *str - '0';
- if (sign > 0 && (n > MAX_DIV || (n == MAX_DIV && c >= MAX_R)))
- {
- n = MAX;
- break;
- }
- else if (sign < 0 && (n > MIN_DIV || (n == MIN_DIV && c >= MIN_R)))
- {
- n = MIN;
- break;
- }
- n = n * 10 + c;
- ++str;
- }
- return sign > 0 ? n : -n;
0 0
- 字符串转换为数字(完整标准版)
- 字符串转换为数字
- 字符串转换为数字
- 字符串转换为数字
- 字符串转换为数字
- 字符串转换为数字
- 字符串转换为数字
- 数字转换为字符串(itoa函数)
- C 数字转换为字符串 字符串转换为数字
- 字符串转换为数字与数字转换为字符串库函数
- 转换文本框字符串为数字
- 将数字转换为字符串
- 将数字转换为字符串
- 将数字转换为字符串
- js 字符串转换为数字
- 怎样数字转换为字符串?
- 将字符串转换为数字
- 字符串转换为整形数字
- android 学习视频 很全的一套视频 包括实例代码带你了解android
- vim中自动补全的快捷键
- 从乌云看企业安全那些事儿
- Salt-API安装配置及使用
- JS读秒跳转
- 字符串转换为数字(完整标准版)
- Android .mk文件语法解析
- S3C6410+FPGA+RTL8211 驱动
- Redis的配置
- 使用Maven进行Hadoop源代码编译
- 完全免费快速搭建个人www服务器
- JSON与PHP的操作
- eclipse下VI插件viplugin的破解
- 什么是 CAPTCHA