CMU Computer Systems: Bits, Bytes, and Integers

Everything is bits
  • Each bit is 0 or 1
  • By encoding/interpreting sets of bits in various ways
  • Why bits? Electronic Implementation
Encoding Byte Values
  • Byte = 8 bits
    在这里插入图片描述
Boolean Algebra
  • Developed by George Boole in 19th Century
  • Operate on Bit Vectors
  • All of the Properties of Boolean Algebra Apply
Representing & Manipulating Sets
  • Representation
  • Operations
    • & Intersection
    • | Union
    • ^ Symmetric difference
    • ~ Complement
Logic Operations in C
  • Contrast to Logical Operators
    • &&, ||, !
Shift Operations
  • Left Shift: x << y
  • Right Shift: x >> y
  • Undefined Behavior
Numeric Ranges
  • Unsigned Values
  • Two’s Complement Values
  • Other Values
Signed vs. Unsigned in C
  • Constants
  • Casting
Casting Signed <=> Unsigned: Basic Rules
  • Bit pattern is maintained
  • But reinterpreted
  • Can have unexpected effects: adding or subtracting 2^w
Expanding, Truncating: Basic Rules
  • Expanding

    • Unsigned: zeros added
    • Signed: sign extension
    • Both yield expected result
  • Truncating

    • Unsigned/sighed: bits are truncated
    • Result reinterpreted
    • Unsigned: mod operation
    • Signed: similar to mod
    • For small numbers yields expected behavior
Addition, negation, multiplication, shifting
  • Unsigned Addition
  • Two’s Complement Addition
  • Multiplication
    • Unsigned Multiplication
    • Signed Multiplication
  • Power-of-2 Multiply with Shift
  • Unsigned Power-of-2 Divide with Shift
    • >>>: logical shift
    • >>: arithmetical shift
    • Counting Down with Unsigned
    • Use unsigned when performing modular arithmetic or using bits to represent sets
  • Representations in memory, pointers, strings
    • Byte-Oriented Memory Organization
    • Machine Words
    • Word-Oriented Memory Organization
    • Byte Ordering
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值