initial commit
This commit is contained in:
3
.gitattributes
vendored
Normal file
3
.gitattributes
vendored
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
[attr]lfs-file filter=lfs diff=lfs merge=lfs -text
|
||||||
|
|
||||||
|
"*.pdf" lfs-file
|
||||||
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
.vscode
|
||||||
|
.venv
|
||||||
61
notes/1.md
Normal file
61
notes/1.md
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
|
||||||
|
# Bits, Bytes, and Integers
|
||||||
|
|
||||||
|
## Integers
|
||||||
|
|
||||||
|
### Representation
|
||||||
|
|
||||||
|
### Conversion
|
||||||
|
|
||||||
|
**Mapping Between `signed` and `unsigned`**
|
||||||
|
|
||||||
|
Maintain bit pattern
|
||||||
|
|
||||||
|
so the conversion of negative value of the signed or value over the T_MAX results different interpreted value.
|
||||||
|
|
||||||
|
### Expanding, Truncating
|
||||||
|
|
||||||
|
**expanding of $w$-bit signed integer**
|
||||||
|
|
||||||
|
$X = x_{w-1}x_{w-2}\cdots x_0$
|
||||||
|
where $s = x_{w-1}$
|
||||||
|
|
||||||
|
expanding it to $w+k$-bit signed int:
|
||||||
|
|
||||||
|
$X = s_{k}s_{k-1} \cdots s_1 x_{w-1}\cdots x_0,\quad \text{where}\, s_i = s$
|
||||||
|
|
||||||
|
**truncation of $w$-bit signed integer**
|
||||||
|
|
||||||
|
first $k$ bit change
|
||||||
|
|
||||||
|
## C Puzzle
|
||||||
|
|
||||||
|
```c
|
||||||
|
|
||||||
|
int x = foo();
|
||||||
|
int y = bar();
|
||||||
|
|
||||||
|
unsigned ux = x;
|
||||||
|
unsigned uy = y;
|
||||||
|
```
|
||||||
|
|
||||||
|
* `x < 0` -> `((x*2) < 0)`
|
||||||
|
* `false`: underflow
|
||||||
|
* `ux >= 0`
|
||||||
|
* it's converted to `ux >= 0u` so `true` for all ux
|
||||||
|
* `x & 7 == 7` -> `(x << 30) < 0`
|
||||||
|
* `true`
|
||||||
|
* `ux > -1`
|
||||||
|
* `always false`, `-1 = uint_max`
|
||||||
|
* `x > y` -> `-x < -y`
|
||||||
|
* `false`
|
||||||
|
* `x * x >= 0`
|
||||||
|
* `false`
|
||||||
|
* `x > 0 && y > 0` -> `x + y > 0`
|
||||||
|
* `x >= 0` -> `-x <= 0`
|
||||||
|
* `x <= 0` -> `-x >= 0`
|
||||||
|
* `(x|-x) >> 31 == -1`
|
||||||
|
* `ux >> 3 == ux/8`
|
||||||
|
* `x >> 3 == x/8`
|
||||||
|
* `x & (x-1) != 0`
|
||||||
|
* `true`
|
||||||
BIN
pdf/A1.pdf
(Stored with Git LFS)
Normal file
BIN
pdf/A1.pdf
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
pdf/L0.pdf
(Stored with Git LFS)
Normal file
BIN
pdf/L0.pdf
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
pdf/L1.pdf
(Stored with Git LFS)
Normal file
BIN
pdf/L1.pdf
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
pdf/L2.pdf
(Stored with Git LFS)
Normal file
BIN
pdf/L2.pdf
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
pdf/P0_GitLab.pdf
(Stored with Git LFS)
Normal file
BIN
pdf/P0_GitLab.pdf
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
pdf/P0_VBox.pdf
(Stored with Git LFS)
Normal file
BIN
pdf/P0_VBox.pdf
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
pdf/P1.pdf
(Stored with Git LFS)
Normal file
BIN
pdf/P1.pdf
(Stored with Git LFS)
Normal file
Binary file not shown.
Reference in New Issue
Block a user