Chap 2 Representing and Manipulating Information (CS:APP)
--------------------------------------------------------------------------------------------------
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)的更多相关文章
- chapter 2: Representing and manipulating information
C allows conversion between unsigned and signed. The rule is that the underlying bit representation ...
- 《CSAPP》读书杂记 - Chapter 2. Representing and Manipulating Information
1. 一段查看地址内容的代码 代码: #include <stdio.h> typedef unsigned char *byte_pointer; void show_bytes(byt ...
- 深入理解计算机系统 (CS:APP) Lab2 - Bomb Lab 解析
原文地址:https://billc.io/2019/04/csapp-bomblab/ 写在前面 CS:APP是这学期的一门硬核课程,应该是目前接触到最底层的课程了.学校的教学也是尝试着尽量和CMU ...
- CS:APP配套实验 Data Lab
刚刚完成注册博客,想写一篇随笔,方便以后自己回顾.如果恰好也能帮助到你,是我的荣幸. 这次随笔是记载我的计算机系统(CS:APP,Computer Systems:A Programer's Pers ...
- 图文并茂-超详解 CS:APP: Lab3-Attack(附带栈帧分析)
CS:APP:Lab3-ATTACK 0. 环境要求 关于环境已经在lab1里配置过了.lab1的连接如下 实验的下载地址如下 说明文档如下 http://csapp.cs.cmu.edu/3e/at ...
- ubuntu12.04 安装CS:APP Y86模拟器
下的第一UBUNTU12.04下Y86模拟器的安装:(參考http://archive.cnblogs.com/a/1865627/ 作适当改动) 1.安装bison和flex词法分析工具 sudo ...
- 《CS:APP》二进制炸弹实验(phase_1-3)
<深入理解计算机系统>第三章的bomb lab,拆弹实验:给出一个linux的可执行文件bomb,执行后文件要求分别进行6次输入,每一次输入错误都会导致炸弹爆炸,程序终止.需要通过反汇编来 ...
- 深入理解计算机系统 (CS:APP) 缓冲区漏洞实验 – Buffer Lab 解析
原文地址:https://billc.io/2019/05/csapp-cachelab/ 写在前面 这是 CSAPP 官网上的第 4 个实验 buflab,也是学校要求的第三个实验.这个实验比上一个 ...
- 信息的表示和处理 及 CS:APP 15213 datalab
信息的表示和处理 在通用计算机中中,字节作为最为最小 的可寻址的内存单元,而不是访问内存中单独的位. 寻址和字节顺序 big endian (大端法),数据最高字节部分地址在地址处,和人的感觉逻辑相似 ...
随机推荐
- [CF460E]Roland and Rose
题意:给定$n$和$r$,要找$n$个整点,使得他们两两距离的平方和最大,并且所有点到原点的距离必须小于$r$ 很容易猜到答案在凸包上然后暴力找,但证明还是挺妙的 首先转化一下距离平方和 令$\vec ...
- 【枚举】【贪心】 Codeforces Round #398 (Div. 2) B. The Queue
卡题意……妈的智障 一个人的服务时间完整包含在整个工作时间以内. 显然,如果有空档的时间,并且能再下班之前完结,那么直接输出即可,显然取最左侧的空档最优. 如果没有的话,就要考虑“挤掉”某个人,就是在 ...
- 1.7(学习笔记)过滤器(Fliter)
一.过滤器(Fliter)简介 过滤器是位于客户端与服务器之间的滤网,在访问资源时会经过一系列的过滤器, 满足条件则放行,不满足条件的将其拦截. 过滤器可以看做是一个特殊的Servlet,设置了过滤器 ...
- Java高级架构师(一)第15节:带查询的分页、修改和删除页面
@RequestMapping(value="toList",method=RequestMethod.GET) public String toList(@ModelAttrib ...
- display:block什么时候使用
所有的块级元素不需要再在使用display:block定义,块级元素本身的默认属性就是block display:block:比较常用于<a><span>这两个标签,因为他们不 ...
- IO多路复用 select、poll、epoll
什么是IO多路复用 在同一个线程里面, 通过拨开关的方式,来同时传输多个(socket)I/O流. 在英文中叫I/O multiplexing.这里面的 multiplexing 指的其实是在单个线程 ...
- Android Studio 首次安装取消自动下载SDK
一.第一次安装: Android Studio安装完成后,第一次启动AS前,为了避免重新下载新版本的SDK,需要做如下操作: AS启动前,打开安装目录,请先将bin目录的idea.properties ...
- Android Studio 中修改versionCode跟versionName
在Android Studio 中修改versionCode 跟versionName最写了一个新版的软件准备发布到应用平台上,但是versionCode和versionName的值一直修改不成功,在 ...
- 让你的saga更具有可伸缩性(Scaling NServiceBus Sagas)
https://lostechies.com/jimmybogard/2013/03/26/scaling-nservicebus-sagas/ 当我们使用NServiceBus sagas (pro ...
- javascript函数,构造函数。js对象和json的区别。js中this指向问题
函数是由事件驱动的或者当它被调用时执行的可重复使用的代码块.好处:在出现大量程序相同的时候,可以封装为一个function,这样只用调用一次,就能执行很多语句.(1)语法:函数就是包裹在花括号中的代码 ...