unsigned

【MySQL】数据类型之数字相关 -- 2019-08-17 02:57:31

耗尽温柔 提交于 2019-11-27 14:23:52
原文: http://blog.gqylpy.com/gqy/247 " 目录 #. 数值类型 1. 数值范围验证 /. 有符号 /. 无符号 2. int类型显示长度验证 #. 浮点型 1. 验证 /. 建表 /. 精度 #. 日期类型 1. 验证 /. year /. date、time、datatime /. timetamp /. datetime 与 timestamp 区别 /. 注意事项 详见链接 MySQL常用数据类型概括: 1. 数字: 整型: tinyint int bigint 小数: float: 在位数比较短的情况下不精确 double: 在位数比较长的情况下不精确(如:0.000001230123123123 存成:0.000001230000) decimal: 精确,内部原理是以字符串形式去存(如果是使用小数,则推荐使用此方法) 2. 字符串: char(0): 简单粗暴,浪费空间,存取速度快(root 存成 root000000) varchar: 精确,节省空间,存取速度慢 sql优化:创建表时,定长的类型往前放(比如性别),变长的往后放(比如地址或描述信息). >255个字符,超了就把文件路径放到数据库中,比如图片,视频等找一个文件服务器,数据库中只存放路径或url. 3. 事件类型: datatime: 最常用,获取当前日期事件 4.

MySQL 基本数据类型

浪子不回头ぞ 提交于 2019-11-27 14:09:54
前言 本来觉得这篇博客没必要写的,因为 MySQL 官方介绍的很详细。但是最近在设计表的时候遇到一些问题并不是简单的看官方介绍就能够解决的,所以,在这里想给大家看一下。 数据类型 整型 首先,我们看一下 MySQL 5.7 官方给出的每种整数类型所需要的存储空间和数值范围: 这里要注意的是,从实际应用角度, 我们一定要根据实际情况选择最合适的数据类型。 例如: 一个表示布尔类型的 0 和 1 的列,选择 TINYINT(1) 就足够了,但是如果你使用了存储字节数大于 TINYINT 的数据类型就是设计不合理。 数据库和内存不同,以 Java 为例,可以使用 byte 类型的地方使用了 long 类型问题不大,因为绝大多数的对象在程序中都是短命对象,方法执行完毕这块内存区域就被释放了,7 个字节实际上不存在浪不浪费一说。但是数据库作为一个存储系统,8 字节的 BIGINT 据的空间是实实在在的。 整型(N)形式 先看一下 MySQL 5.7 官方介绍 对于整数类型,M 表示最大显示宽度。最大显示宽度为 255. 显示宽度与类型可包含的值范围无关 所以对于整型(N)这种形式,我们只要明白两点: 无论 N 是多少和该类型所占字节数无关 N 表示的是显示宽度,不足的用 0 补足,超过的无视长度而直接显示整个数字,但这要整型设置了 unsigned zerofill 才有效 下面举个例子:

Unsigned Int in Java

橙三吉。 提交于 2019-11-27 14:07:28
问题 I'm trying to implement an existing network protocol which makes heavy use of Unsigned datatypes, which are not supported by Java. What I currently do is for each datatype, chose the next bigger one so that the unsigned number may fit into the positive region and then use byte shifting to get the desired effect. Since this is pretty error prone and for an unsigned long onward I have to use BigInteger which is a lot heavier than expanded types, I was wondering if there isn't a better way to

Would it break the language or existing code if we'd add safe signed/unsigned compares to C/C++?

跟風遠走 提交于 2019-11-27 13:54:06
问题 After reading this question on signed/unsigned compares (they come up every couple of days I'd say): Signed / unsigned comparison and -Wall I wondered why we don't have proper signed unsigned compares and instead this horrible mess? Take the output from this small program: #include <stdio.h> #define C(T1,T2)\ {signed T1 a=-1;\ unsigned T2 b=1;\ printf("(signed %5s)%d < (unsigned %5s)%d = %d\n",#T1,(int)a,#T2,(int)b,(a<b));}\ #define C1(T) printf("%s:%d\n",#T,(int)sizeof(T)); C(T,char);C(T

tls加密管道建立流程的一种实现

对着背影说爱祢 提交于 2019-11-27 13:41:05
//生成随机数 //设置多个公钥、私钥对,通过客户端来协商确定使用哪对 //生成随机数后,用私钥将其加密生成密文 //再利用base64编码将密文转换成字符串 //最后可以json的格式放置到payload中返回给客户端 //握手协商,利用ostringstream将两个随机字符串生成一个 //md5编码,输出16进制格式的数 //将16进制格式的数转化为字符串 //使用xxtea对称加密来交互数据 string GetRandStr() { //生成两个8位数的随机数 struct timeval now; gettimeofday(&now, NULL); srand(now.tv_usec); unsigned int rand1 = (unsigned int)rand(); srand(now.tv_usec + 1); unsigned int rand2 = (unsigned int)rand(); char buff[17]; sprintf(buff,"%08x%08x",rand1,rand2); string strRand ; strRand.insert(0,buff,16); return strRand ; } 来源: https://www.cnblogs.com/share-ideas/p/11366098.html

Why is int rather than unsigned int used for C and C++ for loops?

扶醉桌前 提交于 2019-11-27 12:02:25
This is a rather silly question but why is int commonly used instead of unsigned int when defining a for loop for an array in C or C++? for(int i;i<arraySize;i++){} for(unsigned int i;i<arraySize;i++){} I recognize the benefits of using int when doing something other than array indexing and the benefits of an iterator when using C++ containers. Is it just because it does not matter when looping through an array? Or should I avoid it all together and use a different type such as size_t ? This is a more general phenomenon, often people don't use the correct types for their integers. Modern C has

What is the best way to work around the fact that ALL Java bytes are signed?

≯℡__Kan透↙ 提交于 2019-11-27 11:17:55
In Java, there is no such thing as an unsigned byte. Working with some low level code, occasionally you need to work with bytes that have unsigned values greater than 128, which causes Java to interpret them as a negative number due to the MSB being used for sign. What's a good way to work around this? (Saying don't use Java is not an option) When reading any single value from the array copy it into something like a short or an int and manually convert the negative number into the positive value it should be. byte[] foobar = ..; int value = foobar[10]; if (value < 0) value += 256 // Patch up

Can't get rid of “this decimal constant is unsigned only in ISO C90” warning

Deadly 提交于 2019-11-27 10:50:41
问题 I'm using the FNV hash as a hashing algorithm on my Hash Table implementation but I'm getting the warning in the question title on this line: unsigned hash = 2166136261; I don't understand why this is happening because when I do this: printf("%u\n", UINT_MAX); printf("2166136261\n"); I get this: 4294967295 2166136261 Which seems to be under the limits of my machine... Why do I get the warning and what are my options to get rid of it? 回答1: unsigned hash = 2166136261u; // note the u. You need a

Rootkit与后门隐藏技术

别等时光非礼了梦想. 提交于 2019-11-27 10:38:28
目录 简介 linux虚拟文件系统VFS rootkit的功能 隐藏文件 基本方法 高级方法 系统调用流程 hook sys_getdents sys_getdents的调用树 最底层的方法 隐藏进程 日志修改 @ 简介 Rootkit是一套工具,用于长期获取root权限以及隐藏自己和后门程序。攻击者通过漏洞临时获得root权限后,一般会安装后门和rootkit,以便长期获取权限、收集信息。 linux虚拟文件系统VFS 虚拟文件系统(Virtual File System, 简称 VFS), 是 Linux 内核中的一个软件层。文件,目录、字符设备、块设备、 套接字等在 Unix/Linux 中都是以文件被对待,用户通过libc与kernel的VFS交互。 向上,VFS给用户空间的程序提供彼岸准的文件操作接口; 向下,VFS给不同文件系统提供标准的接口。系统中不同的文件系统依赖 VFS 提供的接口共存、 协同工作。 rootkit的功能 获取权限( 链接 ) 防止受保护的文件被拷贝 隐藏后门程序 隐藏后门进程 清理日志 这些功能的实现原理 基本方法:替换相应的程序,如把cp、ls、ps、log等替换为自己编写的程序,产生隐藏的效果。 高级方法:替换相应程序的系统调用,甚至更底层的函数调用。 下面以隐藏文件为例,介绍如何实现这些功能。 隐藏文件 基本方法 hook ls

函数调用栈与缓冲区溢出

一个人想着一个人 提交于 2019-11-27 10:38:08
目录 进程空间分配 函数调用和返回地址 缓冲区溢出攻击 @ 进程空间分配 每一个进程都有自己的一个进程堆栈空间。在Linux界面执行一个执行码时,Shell进程会fork一个子进程,再调用exec系统调用在子进程中执行该执行码。exec系统调用执行新程序时会把命令行参数和环境变量表传递给main函数,它们在整个进程堆栈空间中的位置如下图所示。 注意:stack区是高地址->低地址,heap区相反。 heap区:程序执行时,按照程序需要动态分配的内存空间。malloc、calloc、realloc。如正在处理的数据,编辑的文档。 stack区:存放程序执行时局部变量、函数调用信息、中断现场保留信息。进程中的不同线程可以共享代码段和数据段,但是都有自己的stack。CPU堆栈段指针会在栈顶根据执行情况进行上下移动。 bss段:未初始化数据段,如未初始化的全局变量、全局静态变量、局部静态变量,程序执行前操作系统将此段初始化为0。 data区:已初始化的全局变量、全局静态变量、局部静态变量 code区:可执行文件和库 一个经典的例子 int a = 0; //全局初始化区 int a = 0; //全局初始化区 char *p1; //全局未初始化区 main() { int b; //栈 char s[] = "abc"; //栈 char *p2; //栈 char *p3 =