Add some bit shifting notes back.
parent
2663b97c55
commit
4e4fce24f7
|
@ -119,7 +119,7 @@
|
|||
"_journal/2024-02-02.md": "a3b222daee8a50bce4cbac699efc7180",
|
||||
"_journal/2024-02-01.md": "3aa232387d2dc662384976fd116888eb",
|
||||
"_journal/2024-01-31.md": "7c7fbfccabc316f9e676826bf8dfe970",
|
||||
"logic/equiv-trans.md": "b22c24a523d2acd4e44083f492c0017b",
|
||||
"logic/equiv-trans.md": "588ef4e5185d2b833997e86ab4e85765",
|
||||
"_journal/2024-02-07.md": "8d81cd56a3b33883a7706d32e77b5889",
|
||||
"algorithms/loop-invariants.md": "cbefc346842c21a6cce5c5edce451eb2",
|
||||
"algorithms/loop-invariant.md": "29f9f9090a3109890d333a78acc18b50",
|
||||
|
@ -160,7 +160,7 @@
|
|||
"logic/boolean-algebra.md": "00dc2cdc93d6b0e0e60c975ba87f8633",
|
||||
"_journal/2024-02-13.md": "6242ed4fecabf95df6b45d892fee8eb0",
|
||||
"_journal/2024-02/2024-02-12.md": "618c0035a69b48227119379236a02f44",
|
||||
"binary/shifts.md": "c2ad95420b3aab03021510d46703ebb2",
|
||||
"binary/shifts.md": "9bbeef29e98c3ab521f44b87528cf5c2",
|
||||
"_journal/2024-02-14.md": "76d1b607470305fb3f00a47b8e9ece27",
|
||||
"_journal/2024-02/2024-02-13.md": "6242ed4fecabf95df6b45d892fee8eb0",
|
||||
"_journal/2024-02-15.md": "575ba46d692795d9606de9e635d1f4ac",
|
||||
|
@ -169,10 +169,10 @@
|
|||
"_journal/2024-02/2024-02-15.md": "16cb7563d404cb543719b7bb5037aeed",
|
||||
"algebra/floor-ceiling.md": "828b11e642d6803a740b58f27ff047cf",
|
||||
"algebra/index.md": "90b842eb694938d87c7c68779a5cacd1",
|
||||
"algorithms/binary-search.md": "08cb6dc2dfb204a665d8e8333def20ca",
|
||||
"algorithms/binary-search.md": "dbbaf8d4be7aabef1ed232c1906b4c99",
|
||||
"_journal/2024-02-17.md": "7c37cb10515ed3d2f5388eaf02a67048",
|
||||
"_journal/2024-02/2024-02-16.md": "e701902e369ec53098fc2deed4ec14fd",
|
||||
"binary/integer-encoding.md": "ed39771ee9de86423f75fda74b8c5aa2",
|
||||
"binary/integer-encoding.md": "ef9e9c7938f9719f8a07d8019e63de56",
|
||||
"combinatorics/index.md": "9a85e8858c50c9797243d6d01e1dcbe7",
|
||||
"_journal/2024-02-18.md": "67e36dbbb2cac699d4533b5a2eaeb629",
|
||||
"_journal/2024-02/2024-02-17.md": "7c37cb10515ed3d2f5388eaf02a67048",
|
||||
|
@ -180,7 +180,7 @@
|
|||
"combinatorics/additive-principle.md": "e968028670f95ee9a7c5499ff7cb6792",
|
||||
"_journal/2024-02-19.md": "30d16c5373deb9cb128d2e7934ae256a",
|
||||
"_journal/2024-02/2024-02-18.md": "67e36dbbb2cac699d4533b5a2eaeb629",
|
||||
"combinatorics/permutations.md": "bde773a70e212e669ff4b8bae0f1d1f0",
|
||||
"combinatorics/permutations.md": "dd746d489d3e7d75cc7284755f7ee970",
|
||||
"combinatorics/combinations.md": "6fc179a9bf4e3958f28c4c3f7da5cda0",
|
||||
"_journal/2024-02-20.md": "b85ba0eeeb16e30a602ccefabcc9763e",
|
||||
"_journal/2024-02/2024-02-19.md": "df1a9ab7ab89244021b3003c84640c78",
|
||||
|
@ -196,7 +196,9 @@
|
|||
"c17/index.md": "78576ee41d0185df82c59999142f4edb",
|
||||
"c17/escape-sequences.md": "ebc63c6cdfbe60bbc2708c1b0c8da8bb",
|
||||
"c17/declarations.md": "46b135d583a992991c889d518fec1c0f",
|
||||
"algorithms/sorting/merge-sort.md": "f66f482e5bd551c765fcba564c938d67"
|
||||
"algorithms/sorting/merge-sort.md": "f66f482e5bd551c765fcba564c938d67",
|
||||
"_journal/2024-02-24.md": "d447c08432793bbda79ae9a50c416ce4",
|
||||
"_journal/2024-02/2024-02-23.md": "0aad297148e8cc4058b48b7e45787ca7"
|
||||
},
|
||||
"fields_dict": {
|
||||
"Basic": [
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
---
|
||||
title: "2024-02-24"
|
||||
---
|
||||
|
||||
- [x] Anki Flashcards
|
||||
- [x] KoL
|
||||
- [ ] Sheet Music (10 min.)
|
||||
- [ ] OGS (1 Life & Death Problem)
|
||||
- [ ] Korean (Read 1 Story)
|
||||
- [ ] Interview Prep (1 Practice Problem)
|
||||
- [ ] Log Work Hours (Max 3 hours)
|
||||
|
||||
* Add back some notes on shifting in preparation of integer arithmetic.
|
|
@ -21,4 +21,4 @@ title: "2024-02-23"
|
|||
* Read through last sections of "Discrete Mathematics: An Open Introduction"'s first chapter.
|
||||
* I took a few notes but didn't pay as close attention to these sections as others.
|
||||
* Leetcode [Decode Ways](https://leetcode.com/problems/decode-ways/solutions/).
|
||||
* Practiced implementing heap sort and quicksort.
|
||||
* Practiced implementing merge sort and quicksort.
|
|
@ -14,6 +14,14 @@ Best Case | $O(1)$
|
|||
Worst Case | $O(\lg{n})$
|
||||
Aux. Memory | $O(1)$
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
What precondition must the input of binary search satisfy?
|
||||
Back: It must already be sorted.
|
||||
Reference: Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambridge, Mass: MIT Press, 2009).
|
||||
<!--ID: 1708781334247-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
What is the best case running time of binary search?
|
||||
|
|
|
@ -36,22 +36,6 @@ Tags: c17
|
|||
<!--ID: 1708177246093-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
What integer values does unsigned encoding represent?
|
||||
Back: Nonnegative values.
|
||||
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
|
||||
<!--ID: 1708177246097-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
What integer values does two's-complement represent?
|
||||
Back: Negative, zero, and positive values.
|
||||
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
|
||||
<!--ID: 1708177246102-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
An integral value of $0_{10}$ likely has what encoding?
|
||||
|
|
|
@ -34,6 +34,22 @@ Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Program
|
|||
<!--ID: 1707854589773-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
How many significant bits are dropped on a left shift by `k`?
|
||||
Back: `k`
|
||||
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
|
||||
<!--ID: 1708784904518-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
How many `0`s exist in the result of a left shift by `k`?
|
||||
Back: At least `k`.
|
||||
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
|
||||
<!--ID: 1708784904521-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
What kinds of right shift operations are there?
|
||||
|
@ -91,15 +107,78 @@ Tags: c17
|
|||
<!--ID: 1707854589813-->
|
||||
END%%
|
||||
|
||||
In C, it is undefined behavior to shift by more than the width $w$ of an integral type. Typically though, only the last $w$ bits are considered in the computation. For example, given `int32_t x`, `(x << 32) = (x << 0)`.
|
||||
In C, it is undefined behavior to shift by more than the width $w$ of an integral type.
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
Ignoring UB, what *typically* happens when shifting an `int32_t` by `k ≥ 32` bits?
|
||||
Back: The shift value is interpreted as `k mod 32`.
|
||||
Assuming two's-complement, what is the result of shifting an `int32_t` value by `32`?
|
||||
Back: It is undefined behavior.
|
||||
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
|
||||
Tags: c17
|
||||
<!--ID: 1707873410777-->
|
||||
<!--ID: 1708785613342-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
Assuming two's-complement, what is the result of shifting an `int32_t` value by `31`?
|
||||
Back: $-2^{31}$
|
||||
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
|
||||
Tags: c17
|
||||
<!--ID: 1708785613370-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
What is the result of shifting an `int32_t` value by `-1`?
|
||||
Back: It is undefined behavior.
|
||||
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
|
||||
Tags: c17
|
||||
<!--ID: 1708785613376-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
What is the result of shifting an `uint32_t` value by `32`?
|
||||
Back: It is undefined behavior.
|
||||
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
|
||||
Tags: c17
|
||||
<!--ID: 1708785613383-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
What is the result of shifting an `uint32_t` value by `31`?
|
||||
Back: $2^{31}$
|
||||
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
|
||||
Tags: c17
|
||||
<!--ID: 1708785613389-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
What is the result of shifting an `uint32_t` value by `-1`?
|
||||
Back: It is undefined behavior.
|
||||
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
|
||||
Tags: c17
|
||||
<!--ID: 1708785613393-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
How is $2^n$ written using bitwise shift operators?
|
||||
Back: `1 << n`
|
||||
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
|
||||
Tags: c17
|
||||
<!--ID: 1708784904524-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
What decimal value does `1 << n` translate to?
|
||||
Back: $2^n$
|
||||
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
|
||||
Tags: c17
|
||||
<!--ID: 1708784904526-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
|
|
|
@ -120,7 +120,7 @@ END%%
|
|||
|
||||
%%ANKI
|
||||
Basic
|
||||
What is $n!$ shorthand for?
|
||||
$n!$ is shorthand for what other closed formula?
|
||||
Back: $\Pi_{k=1}^n k$
|
||||
Reference: Oscar Levin, *Discrete Mathematics: An Open Introduction*, 3rd ed., n.d., [https://discrete.openmathbooks.org/pdfs/dmoi3-tablet.pdf](https://discrete.openmathbooks.org/pdfs/dmoi3-tablet.pdf).
|
||||
<!--ID: 1708366788594-->
|
||||
|
@ -198,12 +198,20 @@ END%%
|
|||
|
||||
%%ANKI
|
||||
Basic
|
||||
How many $k$-permutations are there of $n$ objects?
|
||||
How is the number of $k$-permutations of $n$ objects denoted?
|
||||
Back: $(n)_k$
|
||||
Reference: Oscar Levin, *Discrete Mathematics: An Open Introduction*, 3rd ed., n.d., [https://discrete.openmathbooks.org/pdfs/dmoi3-tablet.pdf](https://discrete.openmathbooks.org/pdfs/dmoi3-tablet.pdf).
|
||||
<!--ID: 1708366788622-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
How is $n!$ written equivalently as a falling factorial?
|
||||
Back: $(n)_n$
|
||||
Reference: Oscar Levin, *Discrete Mathematics: An Open Introduction*, 3rd ed., n.d., [https://discrete.openmathbooks.org/pdfs/dmoi3-tablet.pdf](https://discrete.openmathbooks.org/pdfs/dmoi3-tablet.pdf).
|
||||
<!--ID: 1708781334241-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
How is $(n)_k$ $k$-permutations of $n$ objects derived?
|
||||
|
|
|
@ -611,7 +611,7 @@ END%%
|
|||
|
||||
%%ANKI
|
||||
Basic
|
||||
What is the role of $e$ role in textual substitution $E_e^x$?
|
||||
What is the role of $e$ in textual substitution $E_e^x$?
|
||||
Back: It is the expression that is evaluated and substituted into $E$.
|
||||
Reference: Gries, David. *The Science of Programming*. Texts and Monographs in Computer Science. New York: Springer-Verlag, 1981.
|
||||
<!--ID: 1708347042199-->
|
||||
|
|
Loading…
Reference in New Issue