complement many
This commit is contained in:
48
notes/1.md
48
notes/1.md
@@ -1,9 +1,55 @@
|
||||
|
||||
# Bits, Bytes, and Integers
|
||||
|
||||
In computers, everything consists of bits.
|
||||
By encoding sets of bits in various ways, they made meanings:
|
||||
|
||||
* instructions
|
||||
* and data(numbers, sets, strings, etc..)
|
||||
|
||||
## Boolean Algebra
|
||||
|
||||
* and `A & B`
|
||||
* or `A | B`
|
||||
* not `~A`
|
||||
* xor `A ^ B`
|
||||
|
||||
### in C
|
||||
|
||||
* Shift (`<<`, `>>`)
|
||||
* Left Shift(`<<`)
|
||||
Zero fill on right
|
||||
* Right Shift(`>>`)
|
||||
Logical Shift: zero fill with 0's on left
|
||||
Arithmetic shift Relicate most significant bit on left
|
||||
|
||||
```c {cmd="gcc" args=[-x c $input_file -O0 -m32 -o 1_1.out]}
|
||||
#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
int a = 0x7fffffff;
|
||||
int as = a << 1;
|
||||
printf("shl of %d: %d(%08x)\n", a, as, as);
|
||||
|
||||
|
||||
unsigned b = 0x7fffffff;
|
||||
unsigned bs = b << 1;
|
||||
printf("shl of %u: %u(%08x)\n", b, bs, bs);
|
||||
}
|
||||
```
|
||||
|
||||
```sh {cmd hide}
|
||||
while ! [ -f 1_1.out ]; do sleep .1; done; ./1_1.out
|
||||
```
|
||||
|
||||
## Integers
|
||||
|
||||
### Representation
|
||||
### Representation & Encoding
|
||||
|
||||
* for $w$ bits data $x$
|
||||
|
||||
$$B2U(X)=\sum_{i=0}^{w-1} x_i 2^{i}\quad B2T(X)=-x_{w-1}*2^{w-1} + \sum_{i=0}^{w-2}{x_i 2^i}$$
|
||||
|
||||
|
||||
### Conversion
|
||||
|
||||
|
||||
Reference in New Issue
Block a user