整型

IP地址转换整型(算法练习)

匿名 (未验证) 提交于 2019-12-02 23:43:01
// ipTrans.cpp : 定义控制台应用程序的入口点。 // #include "stdafx.h" #include <windows.h> typedef union { unsigned char data[4]; unsigned int ip; }IP; unsigned int TransIP(char *pstrIp) { IP ipstr = {0}; unsigned char temdata[3] = {0}; int i = 0, k = 0, point = 0, t = 0; while(pstrIp[i] != '\0'){ if(pstrIp[i] != '.') { if(point > 0) { ipstr.data[k++] = (temdata[0] - '0')*100 + (temdata[1] - '0')*10 +(temdata[2] - '0'); point = 0; t = 0; } temdata[t++] = pstrIp[i]; } else { point++; } i++; } ipstr.data[k] = (temdata[0] - '0')*100 + (temdata[1] - '0')*10 +(temdata[2] - '0'); return ipstr.ip; } int _tmain(int

python学习笔记之浮点数字符串转化为整数时报错

那年仲夏 提交于 2019-12-02 19:01:33
调用int()函数转整型时,报错如下: >>> int('1.25') Traceback (most recent call last): File "<pyshell#42>", line 1, in <module> int('1.25') ValueError: invalid literal for int() with base 10: '1.25' 原因: ‘1.25’ 为浮点数字符串,不能求值为整型 正确使用方法,直接浮点数型转整型,或者先转浮点数型后转整型 >>> int(float('1.25')) 1 >>> int(1.25) 1 来源: https://www.cnblogs.com/dulilearn/p/11759026.html

Python(1) 整型与浮动型

亡梦爱人 提交于 2019-11-29 19:23:48
整型与浮动型 整数/浮动数=浮点型 整数/整数 = 浮点型 例如: >>> type(1/1) <class 'float'> >>> type(1/1.0) <class 'float'> 整数*整数=整数 整数*浮点数 = 浮点数 <class 'float'> >>> type(1*1) <class 'int'> >>> type(1*1.0) <class 'float'> 整数+-整数=整数 整数+-浮点数 = 浮点数 >>> type(1+1) <class 'int'> >>> type(1+1.0) <class 'float'> >>> type(1-1) <class 'int'> >>> type(1-1.0) <class 'float'> 来源: https://www.cnblogs.com/guangzhou11/p/11529347.html

python—基础—数据类型

倾然丶 夕夏残阳落幕 提交于 2019-11-29 15:08:00
1.数字 整数 int(integer) Python2 区分整型与长整型 整型 长整型 python3 已经不区分整型与长整型,统一叫整型 浮点型 float(带小数点的数字等) 复数 complex (复数由实数部分和虚数部分组成,例:X+YJ,其中Y是复数 的的虚数部分,这里的X和Y都是实数) 2.布尔值 真和假 0和1 真 true 假 false 3.字符串 salary.isdigit() 计算机中,一切皆为对象。 世界万物,皆为对象,一切对象皆可分类。 来源: https://blog.csdn.net/jia1083661/article/details/100673595

c++整型

流过昼夜 提交于 2019-11-29 05:52:43
c++整型包括short,char,int,long,long long。包括有符号和无符号共十种。 今天做题时竟然以为char不是整型,导致本可以用switch简单实现却使用了if else结构。 另外,string类中一个字符是char型不是string型,这点与python不同。 来源: https://www.cnblogs.com/cqu-qxl/p/11457318.html