1. Bit, Binary digit, codes
  2. Data type
    1. unsigned integer
    2. signed integer
    3. logical variable
    4. floating point number
    5. ASCII code

:::warning

BIT

  • 0 and 1 are binary digit
  • BIT stand for Binary Digit :::

Signed Ineger

2’s complement 二补数,补码

  • Given n bits, 2’s complement can only represents 2^n numbers, $-2^{n-1} \le x \le 2^{n-1} - 1$
  • Make sure, say that -3 + 3 = 0 | 0000 | 0 | | —- | —- | | 0001 | 1 | | 0010 | 2 | | … | … | | 0111 | 7 | | 1000 | -8 | | 1001 | -7 | | … | … | | 1110 | -2 | | 1111 | -1 |

:::warning

OVERFLOW

  • the case like -4 + -5 = +7, but not -9

    SIGN EXTENSION

    Different bits number operate together, which isn’t work.
    For example, a 4-bit number plus a 8-bit number. So we should turn a 4-bit number to 8-bit number.

  • Method to turn, which is called SIGN EXTENTION

    • if positive, add 0 at the front
    • if negative, add 1 at the front

01001100 | 76
11111011 | -5
01000111 | 71 :::

Conversion between Binary and Decimal

Chapter 2 Bits, Data Types, and Operations - 图1

Logical Variable

  • can be represented by one bit
  • BIT VECTOR, a batch of logical variable

Component

  • NOT

truth table

x f(x)
0 1
1 0
  • OR

truth table

INPUT COMBINATION
x y f(x, y)
0 0 0
0 1 0
1 0 0
1 1 1
  • AND

truth table

INPUT COMBINATION
x y f(x, y)
0 0 0
0 1 1
1 0 1
1 1 1

:::warning

De Morgan’s Law

Chapter 2 Bits, Data Types, and Operations - 图2 :::

  • XOR / Exclusive-OR

truth table

INPUT COMBINATION
x y f(x, y)
0 0 0
0 1 1
1 0 1
1 1 0
  • XNOR / Exclusive -NOR Equivalence

truth table

INPUT COMBINATION
x y f(x, y)
0 0 1
0 1 0
1 0 0
1 1 1