From 4a4c1a30da18df962113a8391d7d4c06f2d22ed7 Mon Sep 17 00:00:00 2001 From: Joshua Potter Date: Wed, 14 Feb 2024 12:08:10 -0700 Subject: [PATCH] More on printf. --- .../plugins/obsidian-to-anki-plugin/data.json | 12 ++- notes/_journal/2024-02-14.md | 15 +++ notes/_journal/{ => 2024-02}/2024-02-13.md | 0 notes/algorithms/order-growth.md | 2 +- notes/binary/hexadecimal.md | 16 +++- notes/binary/index.md | 2 +- notes/c/strings.md | 93 ++++++++++++++++++- 7 files changed, 128 insertions(+), 12 deletions(-) create mode 100644 notes/_journal/2024-02-14.md rename notes/_journal/{ => 2024-02}/2024-02-13.md (100%) diff --git a/notes/.obsidian/plugins/obsidian-to-anki-plugin/data.json b/notes/.obsidian/plugins/obsidian-to-anki-plugin/data.json index b382148..1d88baa 100644 --- a/notes/.obsidian/plugins/obsidian-to-anki-plugin/data.json +++ b/notes/.obsidian/plugins/obsidian-to-anki-plugin/data.json @@ -119,12 +119,12 @@ "algorithms/loop-invariants.md": "cbefc346842c21a6cce5c5edce451eb2", "algorithms/loop-invariant.md": "d883dfc997ee28a7a1e24b995377792b", "algorithms/running-time.md": "5efc0791097d2c996f931c9046c95f65", - "algorithms/order-growth.md": "ac89d74204040a7c9b870e865c62aa59", + "algorithms/order-growth.md": "5fb2e3ccfc3710be7396a37da7c4f162", "_journal/2024-02-08.md": "19092bdfe378f31e2774f20d6afbfbac", "algorithms/sorting/selection-sort.md": "73a077a726afd376650d1bd9e2d0bed9", "algorithms/index 1.md": "6fada1f3d5d3af64687719eb465a5b97", - "binary/hexadecimal.md": "033246347c06b6911ea497ce6da25263", - "binary/index.md": "4c12fdcd93422987d499cd193737b4c1", + "binary/hexadecimal.md": "c3d485f1fd869fe600334ecbef7d5d70", + "binary/index.md": "27bdd4423e323cd961ddb307ab28d977", "_journal/2024-02-09.md": "a798d35f0b2bd1da130f7ac766166109", "c/types.md": "cf3e66e5aee58a94db3fdf0783908555", "logic/quantification.md": "37655276de8da531ca2b12706a639224", @@ -149,13 +149,15 @@ "_journal/2024-02/2024-02-11.md": "afee9f502b61e17de231cf2f824fbb32", "encoding/ascii.md": "c01e50f96d0493d94dc4d520c0b6bb71", "encoding/index.md": "071cfa6a5152efeda127b684f420d438", - "c/strings.md": "1956bbfd6af40655f945621e4c14fd43", + "c/strings.md": "e08be6bdc820ec4903480a736448a5d7", "logic/truth-tables.md": "7892ceaa416c9a65acc79ca1e6ff778f", "logic/short-circuit.md": "26d300f407f14883022d0ef8dc4f7300", "logic/boolean-algebra.md": "c5d699d407e03d280aa1f201bc3e8b02", "_journal/2024-02-13.md": "6242ed4fecabf95df6b45d892fee8eb0", "_journal/2024-02/2024-02-12.md": "618c0035a69b48227119379236a02f44", - "binary/shifts.md": "24a1f56268fdbae4fe22e92c18366abc" + "binary/shifts.md": "24a1f56268fdbae4fe22e92c18366abc", + "_journal/2024-02-14.md": "22dbfc7f440d63a3c5685a3d32ab9c72", + "_journal/2024-02/2024-02-13.md": "6242ed4fecabf95df6b45d892fee8eb0" }, "fields_dict": { "Basic": [ diff --git a/notes/_journal/2024-02-14.md b/notes/_journal/2024-02-14.md new file mode 100644 index 0000000..21cc131 --- /dev/null +++ b/notes/_journal/2024-02-14.md @@ -0,0 +1,15 @@ +--- +title: "2024-02-14" +--- + +- [x] Anki Flashcards +- [x] KoL +- [ ] Sheet Music (10 min.) +- [ ] OGS (1 Life & Death Problem) +- [x] Korean (Read 1 Story) +- [ ] Interview Prep (1 Practice Problem) +- [x] Log Work Hours (Max 3 hours) + +* More flashcards on `printf`. This time on flags. +* Read 금덩이를 버린 형제 (Two brothers Who Threw Away Their Lumps of Gold). +* Flashcards are growing much more rapidly with my Obsidian_to_Anki plugin approach. Increased new card limit to 40 and will evaluate how well that works. \ No newline at end of file diff --git a/notes/_journal/2024-02-13.md b/notes/_journal/2024-02/2024-02-13.md similarity index 100% rename from notes/_journal/2024-02-13.md rename to notes/_journal/2024-02/2024-02-13.md diff --git a/notes/algorithms/order-growth.md b/notes/algorithms/order-growth.md index 3b57487..4375cc2 100644 --- a/notes/algorithms/order-growth.md +++ b/notes/algorithms/order-growth.md @@ -13,7 +13,7 @@ The **running time** of an algorithm is usually considered as a function of its %%ANKI Basic -How is the running time of a program traditionally measured? +How is the running time of a program measured as a function? Back: As a function of its input size. Reference: Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambridge, Mass: MIT Press, 2009). diff --git a/notes/binary/hexadecimal.md b/notes/binary/hexadecimal.md index 1805cc0..ae79fbc 100644 --- a/notes/binary/hexadecimal.md +++ b/notes/binary/hexadecimal.md @@ -57,7 +57,7 @@ END%% %%ANKI Basic -*When* should padding be introduced on converting binary to hexadecimal? +*When* should padding be introduced in binary to hexadecimal conversion? Back: When the number of bits is not a multiple of `4`. Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. @@ -65,7 +65,7 @@ END%% %%ANKI Basic -*Where* is padding introduced on binary to hexadecimal conversion? +*Where* is padding introduced in binary to hexadecimal conversion? Back: To the left of the binary sequence. Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. @@ -81,7 +81,7 @@ END%% %%ANKI Basic -What are the possible values the first nibble of $2^n$ can take on? +What are the possible values in binary that the first nibble of $2^n$ can take on? Back: `0001`, `0010`, `0100`, and `1000`. Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. @@ -90,7 +90,7 @@ END%% %%ANKI Basic How is $j$ interpreted in the hex representation of $2^{i + 4j}$? -As the number of `0`s in the encoding. +Back: As the number of `0`s in the encoding. Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. END%% @@ -151,6 +151,14 @@ Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Program END%% +%%ANKI +Basic +When does repeated division in decimal to hex conversion end? +Back: When the quotient (*not* the remainder) is `0`. +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. + +END%% + %%ANKI Basic How is e.g. `0xAC32` expressed as a sum of decimal values? diff --git a/notes/binary/index.md b/notes/binary/index.md index d430304..30f94fd 100644 --- a/notes/binary/index.md +++ b/notes/binary/index.md @@ -38,7 +38,7 @@ END%% %%ANKI Basic Why does converting from e.g. decimal to another base involve repeated division? -Back: The position of a digit corresponds to the base raised to the position. +Back: The position of a digit corresponds to the base raised to that position. Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. END%% \ No newline at end of file diff --git a/notes/c/strings.md b/notes/c/strings.md index 45c9a64..9103af0 100644 --- a/notes/c/strings.md +++ b/notes/c/strings.md @@ -44,7 +44,98 @@ END%% ## `printf` -The syntax for the format placeholder is `%[param][flags][width][.precision][length]specifier`. +The syntax for the format placeholder is `%[flags][width][.precision][length]specifier`. + +Flag | Description +--------- | ----------- +`-` | Left-aligns the output +`+` | Prepends a plus for positive signed-numeric types +`␣` | Prepends a space for positive signed-numeric types +`0` | Prepends zeros for numeric types + +%%ANKI +Cloze +The {`-`} flag {left-aligns the output}. +Reference: “Printf,” in *Wikipedia*, January 18, 2024, [https://en.wikipedia.org/w/index.php?title=Printf&oldid=1196716962](https://en.wikipedia.org/w/index.php?title=Printf&oldid=1196716962). + +END%% + +%%ANKI +Basic +The `-` flag overrides what default behavior? +Back: Output is right-aligned by default. +Reference: “Printf,” in *Wikipedia*, January 18, 2024, [https://en.wikipedia.org/w/index.php?title=Printf&oldid=1196716962](https://en.wikipedia.org/w/index.php?title=Printf&oldid=1196716962). + +END%% + +%%ANKI +Cloze +The {`+`} flag {prepends a plus for positive signed-numeric types}. +Reference: “Printf,” in *Wikipedia*, January 18, 2024, [https://en.wikipedia.org/w/index.php?title=Printf&oldid=1196716962](https://en.wikipedia.org/w/index.php?title=Printf&oldid=1196716962). + +END%% + +%%ANKI +Basic +The `+` flag overrides what default behavior? +Back: Nothing is prepended to positive signed-numeric types by default. +Reference: “Printf,” in *Wikipedia*, January 18, 2024, [https://en.wikipedia.org/w/index.php?title=Printf&oldid=1196716962](https://en.wikipedia.org/w/index.php?title=Printf&oldid=1196716962). + +END%% + +%%ANKI +Cloze +The {`␣`} flag {prepends a space for positive signed-numeric types}. +Reference: “Printf,” in *Wikipedia*, January 18, 2024, [https://en.wikipedia.org/w/index.php?title=Printf&oldid=1196716962](https://en.wikipedia.org/w/index.php?title=Printf&oldid=1196716962). + +END%% + +%%ANKI +Basic +The `␣` flag overrides what default behavior? +Back: Nothing is prepended to positive signed-numeric types by default. +Reference: “Printf,” in *Wikipedia*, January 18, 2024, [https://en.wikipedia.org/w/index.php?title=Printf&oldid=1196716962](https://en.wikipedia.org/w/index.php?title=Printf&oldid=1196716962). + +END%% + +%%ANKI +Basic +How do the `+` and `␣` flags relate to one another? +Back: Both prepend a character to positive signed-numeric types. +Reference: “Printf,” in *Wikipedia*, January 18, 2024, [https://en.wikipedia.org/w/index.php?title=Printf&oldid=1196716962](https://en.wikipedia.org/w/index.php?title=Printf&oldid=1196716962). + +END%% + +%%ANKI +Basic +What happens if both the `+` and `␣` flags are specified? +Back: The `+` flag takes precedence. +Reference: “Printf,” in *Wikipedia*, January 18, 2024, [https://en.wikipedia.org/w/index.php?title=Printf&oldid=1196716962](https://en.wikipedia.org/w/index.php?title=Printf&oldid=1196716962). + +END%% + +%%ANKI +Cloze +The {`0`} flag {prepends zeros for numeric types}. +Reference: “Printf,” in *Wikipedia*, January 18, 2024, [https://en.wikipedia.org/w/index.php?title=Printf&oldid=1196716962](https://en.wikipedia.org/w/index.php?title=Printf&oldid=1196716962). + +END%% + +%%ANKI +Basic +What option must be specified for the `0` flag to take effect? +Back: The "width" option. +Reference: “Printf,” in *Wikipedia*, January 18, 2024, [https://en.wikipedia.org/w/index.php?title=Printf&oldid=1196716962](https://en.wikipedia.org/w/index.php?title=Printf&oldid=1196716962). + +END%% + +%%ANKI +Basic +The `0` flag overrides what default behavior? +Back: Spaces are used to match the "width" option by default. +Reference: “Printf,” in *Wikipedia*, January 18, 2024, [https://en.wikipedia.org/w/index.php?title=Printf&oldid=1196716962](https://en.wikipedia.org/w/index.php?title=Printf&oldid=1196716962). + +END%% Specifier | Description --------- | -----------