From 07097ccc7b858a73622b1c1b0909246216450527 Mon Sep 17 00:00:00 2001 From: Joshua Potter Date: Tue, 13 Feb 2024 18:23:48 -0700 Subject: [PATCH] Notes on binary shifting. --- .../plugins/obsidian-to-anki-plugin/data.json | 6 +-- notes/_journal/2024-02-13.md | 3 +- notes/binary/index.md | 2 + notes/binary/shifts.md | 40 ++++++++++++++++++- 4 files changed, 46 insertions(+), 5 deletions(-) diff --git a/notes/.obsidian/plugins/obsidian-to-anki-plugin/data.json b/notes/.obsidian/plugins/obsidian-to-anki-plugin/data.json index 6cc0c80..b382148 100644 --- a/notes/.obsidian/plugins/obsidian-to-anki-plugin/data.json +++ b/notes/.obsidian/plugins/obsidian-to-anki-plugin/data.json @@ -124,7 +124,7 @@ "algorithms/sorting/selection-sort.md": "73a077a726afd376650d1bd9e2d0bed9", "algorithms/index 1.md": "6fada1f3d5d3af64687719eb465a5b97", "binary/hexadecimal.md": "033246347c06b6911ea497ce6da25263", - "binary/index.md": "3c672f105d6a98b21f66547d0731c1ab", + "binary/index.md": "4c12fdcd93422987d499cd193737b4c1", "_journal/2024-02-09.md": "a798d35f0b2bd1da130f7ac766166109", "c/types.md": "cf3e66e5aee58a94db3fdf0783908555", "logic/quantification.md": "37655276de8da531ca2b12706a639224", @@ -153,9 +153,9 @@ "logic/truth-tables.md": "7892ceaa416c9a65acc79ca1e6ff778f", "logic/short-circuit.md": "26d300f407f14883022d0ef8dc4f7300", "logic/boolean-algebra.md": "c5d699d407e03d280aa1f201bc3e8b02", - "_journal/2024-02-13.md": "ed5e2692c31226489d1115d301c660ef", + "_journal/2024-02-13.md": "6242ed4fecabf95df6b45d892fee8eb0", "_journal/2024-02/2024-02-12.md": "618c0035a69b48227119379236a02f44", - "binary/shifts.md": "c9237b5b949519694ab55deb9b740bd1" + "binary/shifts.md": "24a1f56268fdbae4fe22e92c18366abc" }, "fields_dict": { "Basic": [ diff --git a/notes/_journal/2024-02-13.md b/notes/_journal/2024-02-13.md index 42ca46d..c1827b3 100644 --- a/notes/_journal/2024-02-13.md +++ b/notes/_journal/2024-02-13.md @@ -14,4 +14,5 @@ title: "2024-02-13" * Copied over my bash and neovim configs onto my desktop. * Continued practicing One Summer's Day. * Read 혹부리 할아버지 (The Old Man with the Lump). -* Begin adding notes/flashcards on `printf`. It's format specifier is used in enough places to warrant it. \ No newline at end of file +* Begin adding notes/flashcards on `printf`. It's format specifier is used in enough places to warrant it. +* Started playing Nier Automata. \ No newline at end of file diff --git a/notes/binary/index.md b/notes/binary/index.md index 388c07f..d430304 100644 --- a/notes/binary/index.md +++ b/notes/binary/index.md @@ -1,5 +1,7 @@ --- title: Binary +TARGET DECK: Obsidian::STEM +FILE TAGS: binary tags: - binary --- diff --git a/notes/binary/shifts.md b/notes/binary/shifts.md index 415adfa..afe24c3 100644 --- a/notes/binary/shifts.md +++ b/notes/binary/shifts.md @@ -156,6 +156,44 @@ Tags: c 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)`. + +%%ANKI +Basic +According to the C standard, 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: c + +END%% + +%%ANKI +Basic +According to the C standard, what is the result of shifting an `int32_t` value by a negative value? +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: c + +END%% + +%%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`. +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. +Tags: c + +END%% + +%%ANKI +Basic +How is $x \bmod 2^k$ equivalently written as a bit mask? +Back: `x & (k - 1)` +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. +Tags: c + +END%% + ## References -* Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. \ No newline at end of file +* Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.