当前位置: 首页 > 编程日记 > 正文

从1的补码说起计算机的数制

字节换算

bit(b)=位

字节(byte)=8位 -128~127 0~255

半字=2字节=16位 -32768~32767 0~65,535

字(word)=4字节=32位 -2147483848~2147483647 0~4,294,967,295

双字=8字节=64位 -9223372036854775808~9223372036854775807 0~18,446,744,073,709,551,615

十进制-1的二进制表示

在IA-32平台使用补码表示带符号的整数

反码:无符号整数相反代码1->0;0->1。

补码:反码+1

过程

在一个字节中1

二进制是0000 0001

反码 1111 1110

补码 1111 1111 即-1

补码从1111 1111 开始递减直到1000 0000表示-128

一个 16位的1的二进制是

0000 0000 0000 0001

补码即-1是

1111 1111 1111 1111

注意不要把8位的1111 1111即-1和15位的1111 1111 1111 1111即-1混淆!同时16位中1111 1111是255

16位编译器和32位编译器

16位下int 2个字节 long 4个字节 short 2个字节

32位下int4个字节 long 4个字节 short 2个字节

64位下int4个字节 long 8个字节 short 2个字节

printf( "size of \"short\" =%lu\n", sizeof(short));    
printf( "size of \"char\" =%lu\n", sizeof(char));    
printf( "size of \"long\" =%lu\n", sizeof(long));    
printf( "size of \"double\" =%lu\n", sizeof(double));    
printf( "size of \"int\" =%lu\n", sizeof(int));    
printf( "bit of \"int\" =%lu\n", sizeof(int)*8);

32位和64位下输出比较

各种常数 规则 范例
十进制 一般十进制格式 1234
二进制 以0b开头 0b00111010
八进制 以O开头 O056
十六进制 以开0x头 0x56ab
无正负号整数常数 结尾加上U 300U
长整数常数 结尾加上L 300L
无正负号整数常数 结尾加上UL 300UL
浮点数常数 结尾加上F 4.32F
字符常数 单引号中的文字 ‘a’
字符串常数 双引号中的文字 “hello”

int和Long等的最大最小值MAX和MIN可以参考 limits.h

#whereis limits.h

limits: /usr/include/limits.h

32位下的
limits.h

/**	ISO C99 Standard: 7.10/5.2.4.2.1 Sizes of integer types	<limits.h>*/#ifndef _LIBC_LIMITS_H_
#define _LIBC_LIMITS_H_	1#include <features.h>/* Maximum length of any multibyte character in any locale.We define this value here since the gcc header does not definethe correct value.  */
#define MB_LEN_MAX	16/* If we are not using GNU CC we have to define all the symbols ourself.Otherwise use gcc's definitions (see below).  */
#if !defined __GNUC__ || __GNUC__ < 2/* We only protect from multiple inclusion here, because all the other#include's protect themselves, and in GCC 2 we may #include_next throughmultiple copies of this file before we get to GCC's.  */
# ifndef _LIMITS_H
#  define _LIMITS_H	1#include <bits/wordsize.h>/* We don't have #include_next.Define ANSI <limits.h> for standard 32-bit words.  *//* These assume 8-bit `char's, 16-bit `short int's,and 32-bit `int's and `long int's.  *//* Number of bits in a `char'.	*/
#  define CHAR_BIT	8/* Minimum and maximum values a `signed char' can hold.  */
#  define SCHAR_MIN	(-128)
#  define SCHAR_MAX	127/* Maximum value an `unsigned char' can hold.  (Minimum is 0.)  */
#  define UCHAR_MAX	255/* Minimum and maximum values a `char' can hold.  */
#  ifdef __CHAR_UNSIGNED__
#   define CHAR_MIN	0
#   define CHAR_MAX	UCHAR_MAX
#  else
#   define CHAR_MIN	SCHAR_MIN
#   define CHAR_MAX	SCHAR_MAX
#  endif/* Minimum and maximum values a `signed short int' can hold.  */
#  define SHRT_MIN	(-32768)
#  define SHRT_MAX	32767/* Maximum value an `unsigned short int' can hold.  (Minimum is 0.)  */
#  define USHRT_MAX	65535/* Minimum and maximum values a `signed int' can hold.  */
#  define INT_MIN	(-INT_MAX - 1)
#  define INT_MAX	2147483647/* Maximum value an `unsigned int' can hold.  (Minimum is 0.)  */
#  define UINT_MAX	4294967295U/* Minimum and maximum values a `signed long int' can hold.  */
#  if __WORDSIZE == 64
#   define LONG_MAX	9223372036854775807L
#  else
#   define LONG_MAX	2147483647L
#  endif
#  define LONG_MIN	(-LONG_MAX - 1L)/* Maximum value an `unsigned long int' can hold.  (Minimum is 0.)  */
#  if __WORDSIZE == 64
#   define ULONG_MAX	18446744073709551615UL
#  else
#   define ULONG_MAX	4294967295UL
#  endif#  ifdef __USE_ISOC99/* Minimum and maximum values a `signed long long int' can hold.  */
#   define LLONG_MAX	9223372036854775807LL
#   define LLONG_MIN	(-LLONG_MAX - 1LL)/* Maximum value an `unsigned long long int' can hold.  (Minimum is 0.)  */
#   define ULLONG_MAX	18446744073709551615ULL#  endif /* ISO C99 */# endif	/* limits.h  */
#endif	/* GCC 2.  */#endif	/* !_LIBC_LIMITS_H_ *//* Get the compiler's limits.h, which defines almost all the ISO constants.We put this #include_next outside the double inclusion check becauseit should be possible to include this file more than once and still getthe definitions from gcc's header.  */
#if defined __GNUC__ && !defined _GCC_LIMITS_H_
/* `_GCC_LIMITS_H_' is what GCC's file defines.  */
# include_next <limits.h>
#endif/* The <limits.h> files in some gcc versions don't define LLONG_MIN,LLONG_MAX, and ULLONG_MAX.  Instead only the values gcc defined forages are available.  */
#if defined __USE_ISOC99 && defined __GNUC__
# ifndef LLONG_MIN
#  define LLONG_MIN	(-LLONG_MAX-1)
# endif
# ifndef LLONG_MAX
#  define LLONG_MAX	__LONG_LONG_MAX__
# endif
# ifndef ULLONG_MAX
#  define ULLONG_MAX	(LLONG_MAX * 2ULL + 1)
# endif
#endif#ifdef	__USE_POSIX
/* POSIX adds things to <limits.h>.  */
# include <bits/posix1_lim.h>
#endif#ifdef	__USE_POSIX2
# include <bits/posix2_lim.h>
#endif#ifdef	__USE_XOPEN
# include <bits/xopen_lim.h>
#endif

64位下的
limits.h

/**	ISO C99 Standard: 7.10/5.2.4.2.1 Sizes of integer types	<limits.h>*/#ifndef _LIBC_LIMITS_H_
#define _LIBC_LIMITS_H_	1#include <features.h>/* Maximum length of any multibyte character in any locale.We define this value here since the gcc header does not definethe correct value.  */
#define MB_LEN_MAX	16/* If we are not using GNU CC we have to define all the symbols ourself.Otherwise use gcc's definitions (see below).  */
#if !defined __GNUC__ || __GNUC__ < 2/* We only protect from multiple inclusion here, because all the other#include's protect themselves, and in GCC 2 we may #include_next throughmultiple copies of this file before we get to GCC's.  */
# ifndef _LIMITS_H
#  define _LIMITS_H	1#include <bits/wordsize.h>/* We don't have #include_next.Define ANSI <limits.h> for standard 32-bit words.  *//* These assume 8-bit `char's, 16-bit `short int's,and 32-bit `int's and `long int's.  *//* Number of bits in a `char'.	*/
#  define CHAR_BIT	8/* Minimum and maximum values a `signed char' can hold.  */
#  define SCHAR_MIN	(-128)
#  define SCHAR_MAX	127/* Maximum value an `unsigned char' can hold.  (Minimum is 0.)  */
#  define UCHAR_MAX	255/* Minimum and maximum values a `char' can hold.  */
#  ifdef __CHAR_UNSIGNED__
#   define CHAR_MIN	0
#   define CHAR_MAX	UCHAR_MAX
#  else
#   define CHAR_MIN	SCHAR_MIN
#   define CHAR_MAX	SCHAR_MAX
#  endif/* Minimum and maximum values a `signed short int' can hold.  */
#  define SHRT_MIN	(-32768)
#  define SHRT_MAX	32767/* Maximum value an `unsigned short int' can hold.  (Minimum is 0.)  */
#  define USHRT_MAX	65535/* Minimum and maximum values a `signed int' can hold.  */
#  define INT_MIN	(-INT_MAX - 1)
#  define INT_MAX	2147483647/* Maximum value an `unsigned int' can hold.  (Minimum is 0.)  */
#  define UINT_MAX	4294967295U/* Minimum and maximum values a `signed long int' can hold.  */
#  if __WORDSIZE == 64
#   define LONG_MAX	9223372036854775807L
#  else
#   define LONG_MAX	2147483647L
#  endif
#  define LONG_MIN	(-LONG_MAX - 1L)/* Maximum value an `unsigned long int' can hold.  (Minimum is 0.)  */
#  if __WORDSIZE == 64
#   define ULONG_MAX	18446744073709551615UL
#  else
#   define ULONG_MAX	4294967295UL
#  endif#  ifdef __USE_ISOC99/* Minimum and maximum values a `signed long long int' can hold.  */
#   define LLONG_MAX	9223372036854775807LL
#   define LLONG_MIN	(-LLONG_MAX - 1LL)/* Maximum value an `unsigned long long int' can hold.  (Minimum is 0.)  */
#   define ULLONG_MAX	18446744073709551615ULL#  endif /* ISO C99 */# endif	/* limits.h  */
#endif	/* GCC 2.  */#endif	/* !_LIBC_LIMITS_H_ *//* Get the compiler's limits.h, which defines almost all the ISO constants.We put this #include_next outside the double inclusion check becauseit should be possible to include this file more than once and still getthe definitions from gcc's header.  */
#if defined __GNUC__ && !defined _GCC_LIMITS_H_
/* `_GCC_LIMITS_H_' is what GCC's file defines.  */
# include_next <limits.h>
#endif/* The <limits.h> files in some gcc versions don't define LLONG_MIN,LLONG_MAX, and ULLONG_MAX.  Instead only the values gcc defined forages are available.  */
#if defined __USE_ISOC99 && defined __GNUC__
# ifndef LLONG_MIN
#  define LLONG_MIN	(-LLONG_MAX-1)
# endif
# ifndef LLONG_MAX
#  define LLONG_MAX	__LONG_LONG_MAX__
# endif
# ifndef ULLONG_MAX
#  define ULLONG_MAX	(LLONG_MAX * 2ULL + 1)
# endif
#endif#ifdef	__USE_POSIX
/* POSIX adds things to <limits.h>.  */
# include <bits/posix1_lim.h>
#endif#ifdef	__USE_POSIX2
# include <bits/posix2_lim.h>
#endif#ifdef	__USE_XOPEN
# include <bits/xopen_lim.h>
#endif

相关文章:

类:认识类的继承

先新建一个 VCL Forms Application 工程, 代码中就已经出现了两个类:一个是 TForm 类; 一个是 TForm1 类; TForm1 继承于 TForm.TForm 是 TForm1 的父类; TForm1 是 TForm 的子类. Codeunit Unit1;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, C…

机器会成为神吗?

作者 | Roman Wiligut翻译 | 天道酬勤&#xff0c;编辑 | Carol出品 | AI科技大本营&#xff08;ID&#xff1a;rgznai100&#xff09;看着科技的飞速发展&#xff0c;我们越来越想知道&#xff0c;到底科技发展有没有极限呢&#xff1f;在我看来&#xff0c;没有。至少在我们的…

1、Linux汇编——初识汇编

2019独角兽企业重金招聘Python工程师标准>>> 前序 本来想Qt能继续坚持下来&#xff0c;可是绕了一大圈&#xff0c;最终还是选择回到学期伊始的Linux汇编编程上来。鉴于图书馆只能借到这本书&#xff0c;虽然不厚&#xff0c;但是内容还是比较实用丰富&#xff0c;作…

汇编语言调用Linux系统调用

首先查找系统调用文件 #find / -name unistd.h /root/linux/include/unistd.h /usr/include/linux/unistd.h /usr/include/sys/unistd.h /usr/include/bits/unistd.h /usr/include/unistd.h 查看系统调用值 /root/linux/include/unistd.h #define __NR_setup 0 /* use…

为什么说Transformer就是图神经网络?

作者 | Chaitanya Joshi译者 | Kolen出品 | AI科技大本营&#xff08;ID:rgznai100&#xff09;前言有些工程师朋友经常问我这样一个问题&#xff1a;“图深度学习听起来很棒&#xff0c;但是现在是否有非常成功的商业案例&#xff1f;是否已经在实际应用中部署&#xff1f;”除…

IIS日志清理CMD版,VBS版,JS版,WSH版

IIS日志清理之IIS日志生成系统(CreateIISLog.vbs) 创建文件夹Function CreateFolder(Folder)On Error Resume NextSet FSO CreateObject("Scripting.FileSystemObject")FSO.CreateFolder(Folder)If Err>0 ThenErr.ClearCreateFolder FalseElseCreateFolder Tr…

make执行过程

make 的执行过程如下&#xff1a; 1.依次读取变量“MAKEFILES”定义的 makefile 文件列表 2.读取工作目录下的 makefile文件&#xff08;根据命名的查找顺序“GNUmakefile”&#xff0c; “makefile”&#xff0c;“Makefile”&#xff0c;首先找到那个就读取那个&#xff09; …

C语言不要重复包含.h头文件和.c文件

1.不要重复包含头文件 --以上出自《C语言程序设计&#xff1a;现代方法(第2版)》 f3.h //#ifndef AE_OK #define AE_OK 0 typedef int ngx_int_t; //#endiff2.h #include "f3.h"f1.h #include "f3.h" test.c #include <stdio.h>#include &…

论推荐系统与精细化运营

作者丨gongyouliu来源 | 大数据与人工智能&#xff08;ID: ai-big-data&#xff09;随着大数据与人工智能(AI)技术的发展与成熟&#xff0c;国家政策层面对大数据与人工智能技术、创新、创业层面的支持&#xff0c;企业越来越意识到数据和AI技术的价值&#xff0c;并逐步认可数…

服务器产品选型与性价比图解

转载于:https://blog.51cto.com/lijichao/229471

解决jsp引用其他项目时出现的 cannot be resolved to a type错误

JSP页面引用其他项目的时候&#xff0c;在jsp页面上写如下代码&#xff1a; <%List<CandleEntity> candleEntities;CandleOperate candleOperate new CandleOperate(DataBaseEntity.getInstance()); %>虽然也添加了引用 <%page import"com.sjzh.xtrader.l…

ATT格式汇编语言

1.编译与链接 方法一&#xff1a;使用as #as -o test.o test.s #ld -o test test.o 方法二&#xff1a;使用gcc #gcc -o test test.s gnu连接器查找_start标签以确定程序的开始&#xff0c;但gcc查找main标签&#xff0c;所以使用gcc要把 _start改为main 2.调试 #as -gsta…

取得Repeater内部控件命令名与命令参数

前台&#xff1a; <table border"0"cellpadding"0"cellspacing"1"class"meet_tbl"><tr class"meet_title bold"><td>会议名称</td><td>制定日期</td><td>删除</td></tr…

Python在计算内存时值得注意的几个问题

作者 | 豌豆花下猫来源 | python猫&#xff08;ID:python_cat&#xff09;我之前的一篇文章&#xff0c;带大家揭晓了 Python 在给内置对象分配内存时的 5 个奇怪而有趣的小秘密。文中使用了sys.getsizeof()来计算内存&#xff0c;但是用这个方法计算时&#xff0c;可能会出现意…

HDU 1816, POJ 2723 Get Luffy Out(2-sat)

HDU 1816&#xff0c; POJ 2723 Get Luffy Out 题目链接 题意&#xff1a;N串钥匙。每串2把&#xff0c;仅仅能选一把。然后有n个大门&#xff0c;每一个门有两个锁&#xff0c;开了一个就能通过&#xff0c;问选一些钥匙&#xff0c;最多能通过多少个门 思路&#xff1a;二分通…

AI战“疫“之路:​揭秘高精准无感测温系统的全栈AI 技术

在这个全民抗疫的特殊时期&#xff0c;今年的春节返潮来得比往年迟了许多。如今不少企业结束了远程办公&#xff0c;开始陆续复工&#xff0c;一时间&#xff0c;无论是重点防控的机场、火车站&#xff0c;还是学校、企业、社区等密集型场所&#xff0c;都安排了密集的防疫驻扎…

关于text段、data段和bss段

根据APUE&#xff0c;程序分为下面的段&#xff1a;.text, data (initialized), bss, stack, heap。 data/bss/text: text段在内存中被映射为只读&#xff0c;但.data和.bss是可写的。 bss是英文Block Started by Symbol的简称&#xff0c;通常是指用来存放程序中未初始化的全局…

091023 T GIX4 项目中的 智能部署 和 智能客户端

先说一下ClickOnce的使用方法&#xff1a;先给一个要发布的工程设置安全和签名。然后发布到iis中。当用户访问该iis目录下的.application文件时,就会自动安装整个应用程序。 再说一下我们目前的应用程序。相对还是比较复杂的&#xff0c;分为框架部分和特定应用程序部分。其中的…

STL学习系列九:Map和multimap容器

1.map/multimap的简介 map是标准的关联式容器&#xff0c;一个map是一个键值对序列&#xff0c;即(key,value)对。它提供基于key的快速检索能力。map中key值是唯一的。集合中的元素按一定的顺序排列。元素插入过程是按排序规则插入&#xff0c;所以不能指定插入位置。map的具体…

人工智能改变未来教育的5大方式!

作者 | Zohaib翻译 | 天道酬勤&#xff0c;编辑 | Carol出品 | AI科技大本营&#xff08;ID&#xff1a;rgznai100&#xff09;科技正在改变着我们的生活、工作和娱乐方式&#xff0c;教育领域也不例外。 人工智能将像大多数其他领域一样全面改变教育领域&#xff0c;这取决于当…

程序在内存中运行的奥秘

简介当丰富多彩的应用程序在计算机上运行&#xff0c;为你每天的工作和生活带来便利时&#xff0c;你是否知道它们是如何在计算机中工作呢&#xff1f;本文用形象的图表与生动的解释&#xff0c;揭示了程序在计算机中运行的奥秘。 内存管理是操作系统的核心功能&#xff0c;无论…

微软虚拟化解决方案课件

微软虚拟化解决方案课件转载于:https://blog.51cto.com/yangzhiguo/231577

【Python 第8课】while

2019独角兽企业重金招聘Python工程师标准>>> 先介绍一个新东西&#xff1a;注释。python里&#xff0c;以“#”开头的文字都不会被认为是可执行的代码。 print “hello world”和 print "hello world" #输出一行字是同样的效果。但后者可以帮助开发者更…

2019年度CSDN博客之星TOP10榜单揭晓,你上榜了吗?

培根说&#xff0c;『读书造成充实的人&#xff0c;会议造成未能觉悟的人&#xff0c;写作造成正确的人』。在短信短视频快速迭代的快时代&#xff0c;更深度的思考、更正确的实践&#xff0c;更成体系的写作与分享&#xff0c;尤显可贵。这里&#xff0c;每一篇博文都是开发者…

objdump查看目标文件构成

objdump objdump是用查看目标文件或者可执行的目标文件的构成的GCC工具 反汇编 #objdump -d cpuid2 对于其中的反汇编代码 左边是机器指令的字节&#xff0c;右边是反汇编结果。显然&#xff0c;所有的符号都被替换成地址了&#xff0c; 注意没有加$的数表示内存地址&#…

jQuery--AJAX传递xml

程序代码$.ajax({ url:Accept.jsp, type:post, //数据发送方式 dataType: xml, //注意这里是xml哦 &#xff0c;不是html ( html比较简单,所以我拿xml做下例子,解释下 )data:text$("#name").val()&datenewDate(), //要传递的数据 timeout: 2000, …

ActionDescriptor 的认识

ActionDescriptor的作用是对Action方法的元数据的描述,通过ActionDescriptor我们可以获取到action方法的相关的名称,所属控制器,方法的参数列表,应用到方法上的特性以及一些筛选器;ActionDescriptor是由ControllerDescriptor类中的FindAction方法进行创建; ActionDescriptor类也…

readelf和ldd分析elf文件

1. elf 文件格式 linux系统中&#xff0c;gcc编译器编译出的object文件、可执行文件都属于elf文件。 elf文件由三个部分组成&#xff1a;elf header、program headers|section headers、sections|program segments。 如果是executable文件&#xff0c;则section部分是不需要的…

号称3个月发布最强量子计算机,卖口罩的霍尼韦尔凭什么?

作者 | Just出品 | AI科技大本营新冠疫情的发生&#xff0c;霍尼韦尔这家口罩品牌引入众人眼帘。但实际上&#xff0c;口罩业务只是这家企业的一小块副业&#xff0c;它能做的业务十分多元。3月4日&#xff0c;霍尼韦尔宣布在量子计算领域取得突破&#xff0c;将提升量子计算机…

一位老工程师前辈的忠告

诸位&#xff0c;咱当工程师也是十余年了&#xff0c;不算有出息&#xff0c;环顾四周&#xff0c;也没有看见几个有出息的&#xff01;回顾工程师生涯&#xff0c;感慨万千&#xff0c;愿意讲几句掏心窝子的话&#xff0c;也算给咱们师弟师妹们提个醒&#xff0c;希望他们比咱…