背景:不同字长的整数进行转换,需要在不改变数的大小的前提下将较小的数据类型转为更大的数据类型。 无符号数的扩展:开头加0即可,也叫零扩展。 有符号数(补码)的扩展:开头添符号位。 1 short sx = -12345; 2 unsigned short usx = sx; 3 int x = sx ...
分类:
其他好文 时间:
2020-01-05 13:57:18
阅读次数:
87
2019年的某月某天某神仙讲了莫队,但是我一直咕咕咕到了2020年 什么是莫队 莫队是一种优雅的暴力,也是用来完成区间询问的。普通莫队复杂度$O(n \sqrt n)$。一种十分优美的离线做法 前置芝士 ~~0.拥有脑子~~ 1.$STL$中$sort$的$cmp$ 2.看/写超长的三目运算符的耐心 ...
分类:
其他好文 时间:
2020-01-04 22:11:51
阅读次数:
95
初始化socket socket是一种系统资源,并不是每次初始化都一定成功,因此为了避免初始化失败,一般使用多次初始化的方式,如下所示: unsigned int times = 0x0; while((server = socket(PF_INET6, SOCK_STREAM, 0)) < 0 & ...
分类:
其他好文 时间:
2020-01-04 10:37:54
阅读次数:
100
1. 查询 创建数据库、数据表 -- 创建数据库 create database python_test_1 charset=utf8; -- 使用数据库 use python_test_1; -- students表 create table students( id int unsigned p ...
分类:
数据库 时间:
2020-01-04 01:23:40
阅读次数:
98
``` #define u8 unsigned char #define u32 unsigned int #define SWAP32(ipValue) ((u32)(((ipValue) & 0xff) > 8) & 0xff00) | \ (((ipValue) >> 24) & 0xff) ... ...
分类:
其他好文 时间:
2020-01-03 14:02:50
阅读次数:
172
下面以unsigned int value = 0x12345678为例,分别看看在两种字节序下其存储情况,我们可以用unsigned char buf[4]来表示value Big-Endian: 低地址存放高位,如下: 高地址 buf[3] (0x78) -- 低位 buf[2] (0x56) ...
分类:
其他好文 时间:
2020-01-02 20:32:57
阅读次数:
77
在C中,默认的基础数据类型均为signed,如定义变量为int,long等,都为有符号的。如果要定义无符号类型,必须显式地在变量类型前加unsigned。 char在我所用的linux中一般都是8位一个字节,表示范围为-128~127。 unsigned char的表示范围为0~255。 而ASCI ...
分类:
编程语言 时间:
2019-12-27 11:57:25
阅读次数:
252
/** * 字符数组模拟大整数取余 a % b *大整数取模 * *思路:首先,将大整数根据秦九韶公式写成“自左向右”的形式:4351 = ((4 * 10 + 3) * 10 + 5) * 10 + 1,然后利用模的性质,逐步取模。 * @param: const unsigned char a[ ...
分类:
其他好文 时间:
2019-12-27 09:24:05
阅读次数:
76
模板 include<cstdio include<cstring include define reg register define F(i,a,b) for(register int (i)=(a);(i) A.双倍回文 维护trans指针,定义和fail不同在于有长度缩小一半的限制,求法也类 ...
分类:
其他好文 时间:
2019-12-26 12:55:04
阅读次数:
81