--------------------------------------------------------------------------------------------------

Author: YuManZI

2014/06/23  1.1-3.5

2014/06/24  3.6-3.8

2014/06/27  4.1

2014/06/28  4.2-4.5

--------------------------------------------------------------------------------------------------

1. Information Storage

1.1 Virtual Memory: a machine-level program views memory as a very large array of bytes.

1.2 Data Sizes (bytes)

32 bit: char 1; short [int] 2; int 4; long [int] 4; long long [int] 8; char *(any pointer) 4; float 4; double 8;

64 bit: char 1; short [int] 2; int 4; long [int]8; long long [int] 8; char *(any pointer)8; float 4; double 8;

Contents within square brackets [] are optional. The main difference between 32 bit and 64 bit machines are following two points: a) different sizes of data type long; b) different sizes of pointers.

1.3 Byte Ordering: big endian & little endian. (Takinh 0x01234567 as example.)

Big endian, the most significant byte comes first(lower address), bytes from low address to high address are 01 23 45 67, respectively;

Little endian, the least significant byte comes first(lower address), bytes from low address to high address are 67 45 23 01, respectively.

1.4 Shift Operations in C

Left shift << k: dropping off the k most significant bits and filling the right end with k zero;

Logical right shift >>k: dropping off the k least significant bits and filling the lest end with k zero;

Arithmetic right shift >>k: dropping off the k least significant bits and filling the lest end with k themost significant bit.

Arithmetic right shift uses the most significant bit as filling unit, because of the two's complement representation of negative integers. In some languages(e.g. java), the number of shifting bits can never be more than bit sizes of data types.

2. Integral Data Types

2.1 Unsigned Encodings (w bits, x=[x_(w-1), x_(w-2),...,x_0])

B2U(x)=sigma{i=[0,w-1]}(x_i*2^i)

B2U means Bits to Unsigned

It can represent integers between [0..2^w-1]

2.2 Two's-Complement Encodings (same setting as 2.1)

B2T(x)=-x_(w-1)*2^(w-1) + sigma{i=[0,w-2]}(x_i*2^i)

B2T means Bits to Two's

It's a signed encoding, can represent integers between [-2^(w-1), 2^(w-1)-1], the difference between it and Unsigned encoddings are the weight of the significant bit, i.e. positive for unsigned and negative for two's-complement.

2.3 Conversions

Signed<-->Unsigned with identical size: the key is to keep bit representation stable;

Large size-> Small size with same type of signed or unsigned: truncate directly;

Chap 2 Representing and Manipulating Information (CS:APP)的更多相关文章

  1. chapter 2: Representing and manipulating information

    C allows conversion between unsigned and signed. The rule is that the underlying bit representation ...

  2. 《CSAPP》读书杂记 - Chapter 2. Representing and Manipulating Information

    1. 一段查看地址内容的代码 代码: #include <stdio.h> typedef unsigned char *byte_pointer; void show_bytes(byt ...

  3. 深入理解计算机系统 (CS:APP) Lab2 - Bomb Lab 解析

    原文地址:https://billc.io/2019/04/csapp-bomblab/ 写在前面 CS:APP是这学期的一门硬核课程,应该是目前接触到最底层的课程了.学校的教学也是尝试着尽量和CMU ...

  4. CS:APP配套实验 Data Lab

    刚刚完成注册博客,想写一篇随笔,方便以后自己回顾.如果恰好也能帮助到你,是我的荣幸. 这次随笔是记载我的计算机系统(CS:APP,Computer Systems:A Programer's Pers ...

  5. 图文并茂-超详解 CS:APP: Lab3-Attack(附带栈帧分析)

    CS:APP:Lab3-ATTACK 0. 环境要求 关于环境已经在lab1里配置过了.lab1的连接如下 实验的下载地址如下 说明文档如下 http://csapp.cs.cmu.edu/3e/at ...

  6. ubuntu12.04 安装CS:APP Y86模拟器

    下的第一UBUNTU12.04下Y86模拟器的安装:(參考http://archive.cnblogs.com/a/1865627/ 作适当改动) 1.安装bison和flex词法分析工具 sudo ...

  7. 《CS:APP》二进制炸弹实验(phase_1-3)

    <深入理解计算机系统>第三章的bomb lab,拆弹实验:给出一个linux的可执行文件bomb,执行后文件要求分别进行6次输入,每一次输入错误都会导致炸弹爆炸,程序终止.需要通过反汇编来 ...

  8. 深入理解计算机系统 (CS:APP) 缓冲区漏洞实验 – Buffer Lab 解析

    原文地址:https://billc.io/2019/05/csapp-cachelab/ 写在前面 这是 CSAPP 官网上的第 4 个实验 buflab,也是学校要求的第三个实验.这个实验比上一个 ...

  9. 信息的表示和处理 及 CS:APP 15213 datalab

    信息的表示和处理 在通用计算机中中,字节作为最为最小 的可寻址的内存单元,而不是访问内存中单独的位. 寻址和字节顺序 big endian (大端法),数据最高字节部分地址在地址处,和人的感觉逻辑相似 ...

随机推荐

  1. Mysql数据库的安装及配置

    本文转载自http://www.cnblogs.com/xiaoluo501395377/archive/2013/04/07/3003278.html 如果要在Linux上做j2ee开发,首先得搭建 ...

  2. Ze_Min Tree 主席树

    前言 主席树,也叫可持久化线段树,所以他的本质是颗线段树,而可持久化指的是这颗线段树可以访问过去某个时刻线段树上的信息. 应用 应用的比较多的是查询区间的第k大值(因为其他的数据结构不好做). 实现 ...

  3. 【kmp算法】poj2406 Power Strings

    如果next[n]<n/2,一定无解. 否则,必须要满足n mod (n-next[n]) = 0 才行,此时,由于next数组的性质,0~n-next[n]-1的部分一定是最小循环节. [ab ...

  4. 十. 图形界面(GUI)设计10.菜单

    有两种类型的菜单:下拉式菜单和弹出式菜单.本章只讨论下拉式菜单编程方法.菜单与JComboBox和JCheckBox不同,它们在界面中是一直可见的.菜单与JComboBox的相同之处是每次只可选择一个 ...

  5. Scala零基础教学【1-20】

    基于王家林老师的Spark教程——共计111讲的<Scala零基础教学> 计划在9月24日内完成(中秋节假期之内) 目前18号初步学习到25讲,平均每天大约完成15讲,望各位监督. 初步计 ...

  6. Mac sublime 编译Python UnicodeEncodeError: 'ascii' codec can't encode characters in position 6-8: ordinal not in range(128)

    刚学Python,想打印个“hello 张林峰”,代码如下: #!/usr/bin/env python3 # -*- coding: utf-8 -*- print('hello 张林峰') 用su ...

  7. JavaScript:this是什么

    JavaScript:this是什么? 定义:this是包含它的函数作为方法被调用时所属的对象. 说明:这句话有点咬嘴,但一个多余的字也没有,定义非常准确,我们可以分3部分来理解它! 1.包含它的函数 ...

  8. 【mybatis】mybatis使用java实体中定义的常量,或静态方法

    mybatis使用java实体中定义的常量 示例代码: <select id="findDealerInfo" parameterType="com.pisen.c ...

  9. 怎样使用libcurl获取隐藏了文件后缀的url网络文件类型

    CURLINFO_CONTENT_TYPE CURL: Get Returned Content Mime Type 例如 :以下代码可以查询出天地图的tile图像类型为jpg "http: ...

  10. postprocessing stack v2

    用了v2和unity2017.3.0f有兼容性问题 在assetbundle的情况下 CopyStd这个shader打不进去 在assetbundle的menafest里面有列但是shader.fin ...